|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello,
I am trying to piece together a script that will do the following: 1. Check status of a service daily 2. Start the service if it is no running 3. Log the actions to a log file I would run this as a scheduled task. I have the following pieces of WMI to: 1. check status of service: strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colRunningServices = objWMIService.ExecQuery _ ("SELECT * FROM Win32_Service WHERE Name = 'someService'") For Each objService in colRunningServices Wscript.Echo objService.DisplayName & ": " & objService.State Next > I would prefer not to have any messsage box appear 2. Start the Service: Set objService = objWMI.Get("Win32_Service.Name='" & strService & "'") WScript.Echo " Starting " & objService.Name objService.StartService() Any help to piece this together into a vbs script would be greatly appreciated! Cheers! |
|
#2
|
|||||||||||||||||
|
|||||||||||||||||
|
You're on the right track. You have all of the code that you need to accomplish this, but you are taking a bit of a run-around approach.
vb Code:
vb Code:
vb Code:
vb Code:
So the complete code looks like this: vb Code:
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! |
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > WMI - Check if service is running and start it |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|