How to write VBS Script to check a website, and then stop and start the Windows service

I need to write a VBS script to check the site for a specific text: "Service is unavailable" and "Error in /"

When he finds this, I will need to restart the World Publishing Service Windows service

Where to begin?

Any help would be greatly appreciated!

Hooray!

Andy

+3
source share
1 answer

You can check the website using the MSXML2.XMLHTTP object (that is, the same object that Internet Explorer uses to run AJAX requests) and check the status code (200 is OK, 404 is not found, etc.)

dim http: set http = CreateObject("MSXML2.XMLHTTP")
http.open "GET", "http://site.com?param=value", false
http.send

if not http.status = 200 then
    ' something not right, start your service
end if

, , ( , ):

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name='NetDDE'")
For each objService in colServiceList
    errReturn = objService.StartService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("Associators of " _
   & "{Win32_Service.Name='NetDDE'} Where " _
        & "AssocClass=Win32_DependentService " & "Role=Dependent" )
For each objService in colServiceList
    objService.StartService()
Next

, , IIS, , , http- , IIS .

+3

Source: https://habr.com/ru/post/1792984/


All Articles