HEELPBOOK - Check status of a windows service on a remote system using WMI #################################### In the automation world, you may be required to check whether the product that you wanted to test is installed and the application service is running properly. You could use the below code to accomplish that. Then call the function with appropriate test parameters. For example: strServiceStatus=sGetServiceStatus "targethostname", "ServiceName" Below is the function (be sure to specify the password and the username of an administrative's user): Function sGetServiceStatus(ByVal strComputer, ByVal strServiceName) if(strComputer = "") then sGetServiceStatus = "" Exit function end if wbemImpersonationLevelImpersonate = 3 wbemAuthenticationLevelPktPrivacy = 6 Set objLocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = objLocator.ConnectServer _ (strComputer, "/root/CIMV2","youradminusername" ,"youradminpassword" objWMIService.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate objWMIService.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy Set colListOfServices = objWMIService.ExecQuery _ ("Select * from Win32_Service Where DisplayName ='"& strServiceName & "'") if(colListOfServices.Count=0) then sGetServiceStatus = "" Exit function end if For Each objItem in colListOfServices If objItem.DisplayName = strServiceName and objItem.State = "Running" Then sGetServiceStatus = objItem.State Exit Function else sGetServiceStatus = objItem.State Exit function End If Next sGetServiceStatus = "" End Function ############ ARTICLE INFO ############# Article Month: June Article Date: 28/06/2012 Permalink: http://heelpbook.altervista.org/2012/check-status-of-a-windows-service-on-a-remote-system-using-wmi/ Source: http://haripotter.wordpress.com/2008/02/28/how-to-retrieve-the-status-of-a-windows-service-using-wmi-with-vbscript/ Language: English View more articles on: http://www.heelpbook.net/ Follow us on Facebook: http://it-it.facebook.com/pages/HeelpBook/100790870008832 Follow us on Twitter: https://twitter.com/#!/HeelpBook Follow us on RSS Feed: http://feeds.feedburner.com/Heelpbook Follow us on Delicious: http://delicious.com/heelpbook