Thursday, July 10, 2008

VBScript To Find All SQL Services And Their State

Save the following script as a .vbs file to display the SQL Services and their current state.

strComputer = "."
strServices = ""
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
("Select * from Win32_Service WHERE DisplayName Like '%sql%'")
For Each objService in colRunningServices
strServices = strServices + objService.DisplayName & VbTab & objService.State & vbcr
Next
Wscript.Echo strServices

0 comments: