thomasmcgeown
Technical User
Good morning.
I am currently working on a script that will check for a service, and check if its running.
If the service is present and not running it will attempt to start the service.
At this point i would like the script to set the startup type to automatic.
Im farily new to WMI so im quite sure the problem is my code, it is not permisions as I am running the script from a domain admin account.
Code i am using is below:
If intTester <> 1 Then
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strNewString & "\root\cimv2"
Set colRunningServices = objWMIService.ExecQuery ("Select * from Win32_Service"
For Each objService in colRunningServices
If objService.DisplayName = "VNC Server" Then
If objService.State = "Running" Then
domystuff
End If
If objService.State= "Stopped" Then
errReturn = objService.StartService()
errReturn = objService.Change(, , , , ,"Auto"
End If
End If
Next
End if
Please forgive any n00b mistakes or sloppy coding!
Thank you in anticipation!
Tom
I am currently working on a script that will check for a service, and check if its running.
If the service is present and not running it will attempt to start the service.
At this point i would like the script to set the startup type to automatic.
Im farily new to WMI so im quite sure the problem is my code, it is not permisions as I am running the script from a domain admin account.
Code i am using is below:
If intTester <> 1 Then
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strNewString & "\root\cimv2"
Set colRunningServices = objWMIService.ExecQuery ("Select * from Win32_Service"
For Each objService in colRunningServices
If objService.DisplayName = "VNC Server" Then
If objService.State = "Running" Then
domystuff
End If
If objService.State= "Stopped" Then
errReturn = objService.StartService()
errReturn = objService.Change(, , , , ,"Auto"
End If
End If
Next
End if
Please forgive any n00b mistakes or sloppy coding!
Thank you in anticipation!
Tom