Does anyone have a WQL query to search for a version of an instance of SQL Server?

Does anyone know how to use WMI to get the version of SQL Server installation (not worrying about the version) in VBScript?

I tried using the registry (but this requires that you know the instance name and version of SQL Server.

I tried using SQL Query (but this requires permissions for the database, and my process uses the LOCAL user without permission on the SQL Server DBMS).

So, I stayed using WQL to query WMI.

I guess I need:

1) request a WMI object (which) to get instance names. 2) Then for each instance, request a different object and pull the version out of it.

I looked at the Microsoft documentation and can not find the objects used.

Can anyone help?

Quietleni

+4
source share
2 answers

Start here: How to change advanced SQL Server service properties using VBScript

First sample:

set wmi = GetObject("WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement10") for each prop in wmi.ExecQuery("select * from SqlServiceAdvancedProperty where SQLServiceType = 1 AND PropertyName = 'VERSION'") WScript.Echo prop.ServiceName & " " & prop.PropertyName & ": " & prop.PropertyStrValue next 

seems to be doing what you asked for. Check out Other Versions if you are not using version 2008.

+2
source

Thanks for this. Here is the script I created. I hope this helps someone else in my position:

 Dim strValueName, strSKUName, strEdition, strVersion, strArchitecture Dim objWMI, objProp On Error Resume Next ' First try SQL Server 2008/2008 R2: Set objWMI = GetObject("WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement10") If Err.Number <> 0 Then ' Next, try SQL Server 2005: Set objWMI = GetObject("WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement") If Err.Number <> 0 Then ' Next, try SQL Server 2012: Set objWMI = GetObject("WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement11") End If End If If Err.Number = 0 Then On Error Goto 0 ' Go through the properties (which is just one) and find the name of the SKU. For Each objProp In objWMI.ExecQuery("select * from SqlServiceAdvancedProperty where SQLServiceType = 1 AND (PropertyName = 'SKUNAME' OR PropertyName = 'VERSION')") If objProp.PropertyName = "SKUNAME" THEN strSKUName = objProp.PropertyStrValue Else strVersion = objProp.PropertyStrValue End If Next ' We do not want the number of bits, so chop it off! If Instr(strSKUName, " (") <> 0 Then strEdition = Left(strSKUName, Instr(strSKUName, " (")) strArchitecture = "64-bit" Else strEdition = strSKUName strArchitecture = "32-bit" End If WScript.Echo strEdition & " / " & strSKUName & " / " & strArchitecture End If 
+2
source

All Articles