mmiller3442
asked on
VBS script to restart IIS on remote server
Hello
I wanted to get a vbs script or a batch file created that would restart IIS on a remote server. I was hoping the batch or VBS script when run it will pop up with a box asking for the server name and after entering the server name it will restart IIS on that remote server
I have the following syntax below to get the pop up box but don't know how to get the rest of the vbs script to execute iisreset
'Get the servername
strServer = InputBox("Please submit the server name","IIS Restart script")
IF strServer = "" THEN
WScript.Echo "No servername was given or you clicked Cancel"
WScript.Quit
END IF
'check if the server is online
Srvpad = "\\"&strServer&"\c$\WINDOW S\system32 "
SET oChksrv = CreateObject("Scripting.Fi leSystemOb ject")
IF oChksrv.FolderExists(Srvpa d) = FALSE THEN
WScript.Echo "Server " & strServer & " doesn't exist or isn't online!"
WScript.Quit
END IF
Any help would be appreciated
I wanted to get a vbs script or a batch file created that would restart IIS on a remote server. I was hoping the batch or VBS script when run it will pop up with a box asking for the server name and after entering the server name it will restart IIS on that remote server
I have the following syntax below to get the pop up box but don't know how to get the rest of the vbs script to execute iisreset
'Get the servername
strServer = InputBox("Please submit the server name","IIS Restart script")
IF strServer = "" THEN
WScript.Echo "No servername was given or you clicked Cancel"
WScript.Quit
END IF
'check if the server is online
Srvpad = "\\"&strServer&"\c$\WINDOW
SET oChksrv = CreateObject("Scripting.Fi
IF oChksrv.FolderExists(Srvpa
WScript.Echo "Server " & strServer & " doesn't exist or isn't online!"
WScript.Quit
END IF
Any help would be appreciated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here's a code for a batchfile
WMIC /node:"servername" service where caption="DNS Client" Call stopservice && WMIC /node:"servername" service where caption="DNS Client" Call startservice
With /user and /password you can define credentials to authenticate
Note: To execute IISReset is a better way to reset the IIS Server than restaring the service
WMIC /node:"servername" service where caption="DNS Client" Call stopservice && WMIC /node:"servername" service where caption="DNS Client" Call startservice
With /user and /password you can define credentials to authenticate
Note: To execute IISReset is a better way to reset the IIS Server than restaring the service
ASKER
Thanks Guys
I'm going to use the VBS script route
I have modified the code below with the service names but the only service that restart is the WWW service, any thoughts?
Else
Set colServiceList = objWMIService.ExecQuery("A ssociators of " & "{Win32_Service.Name='IISA DMIN'} Where " & "AssocClass=Win32_Dependen tService " & "Role=Antecedent" )
For each objService in colServiceList
objService.StopService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("S elect * from Win32_Service where Name='W3SVC'")
For each objService in colServiceList
errReturn = objService.StopService()
Next
WScript.Sleep 10000
Set colServiceList = objWMIService.ExecQuery("S elect * from Win32_Service where Name='W3SVC'")
For each objService in colServiceList
errReturn = objService.StartService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("A ssociators of " & "{Win32_Service.Name='IISA DMIN'} Where " & "AssocClass=Win32_Dependen tService " & "Role=Dependent" )
For each objService in colServiceList
objService.StartService()
Next
WScript.Echo "All operations completed"
End If
I'm going to use the VBS script route
I have modified the code below with the service names but the only service that restart is the WWW service, any thoughts?
Else
Set colServiceList = objWMIService.ExecQuery("A
For each objService in colServiceList
objService.StopService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("S
For each objService in colServiceList
errReturn = objService.StopService()
Next
WScript.Sleep 10000
Set colServiceList = objWMIService.ExecQuery("S
For each objService in colServiceList
errReturn = objService.StartService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("A
For each objService in colServiceList
objService.StartService()
Next
WScript.Echo "All operations completed"
End If
They need to all be the same service make them all IISADMIN and that should do it WWW is the only dependant of W3SVC i think is why it is happening.
ASKER
Made that change below and the only task that initiates is a stop command to WWW. No command is sent to start WWW or any other services
WScript.Quit
Else
Set colServiceList = objWMIService.ExecQuery("A ssociators of " & "{Win32_Service.Name='IISA DMIN'} Where " & "AssocClass=Win32_Dependen tService " & "Role=Antecedent" )
For each objService in colServiceList
objService.StopService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("S elect * from Win32_Service where Name='IISADMIN'")
For each objService in colServiceList
errReturn = objService.StopService()
Next
WScript.Sleep 10000
Set colServiceList = objWMIService.ExecQuery("S elect * from Win32_Service where Name='IISADMIN'")
For each objService in colServiceList
errReturn = objService.StartService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("A ssociators of " & "{Win32_Service.Name='IISA DMIN'} Where " & "AssocClass=Win32_Dependen tService " & "Role=Dependent" )
For each objService in colServiceList
objService.StartService()
Next
WScript.Echo "All operations completed"
WScript.Quit
Else
Set colServiceList = objWMIService.ExecQuery("A
For each objService in colServiceList
objService.StopService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("S
For each objService in colServiceList
errReturn = objService.StopService()
Next
WScript.Sleep 10000
Set colServiceList = objWMIService.ExecQuery("S
For each objService in colServiceList
errReturn = objService.StartService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("A
For each objService in colServiceList
objService.StartService()
Next
WScript.Echo "All operations completed"
It possible we are not waiting long enough for the services to stop. Please adjust the sleep numbers to all be 45000 that is 45 seconds between steps. The other thing you can do is to do it manually and time them out and see what works.
Open in new window