I am playing with System Centre Operations Manager and Config Manager. They all use VBS to determine if SQL Server is present, but often fall foul of a stopped SQL Server service or a different major version (Sql 2008 v Sql 2005)and are very wordy – some 75 lines of code in the configuration Items for DCM!

For example the downloadable DCM packs for SQL Server only largely work on SQL 2005. Really we need them to work in any edition or at least 200x.

So here is a one line VBS script I have started using to detect if SQL Server Service is installed and running (any  version)

If GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select Name from Win32_Service where state='Running' and PathName like '%sqlservr.exe%'", "WQL", &H10).Count > 1 Then WScript.Echo “True”

Works great in System Centre Configuration Manager as a Detection Method for SQL Server. A sample screenshot in config manager is below.