Thursday, March 15, 2007

Query a Machine's OS Using WMI

Say you need to automatically configure a bunch of servers with varying operating systems. The configuration you specify will vary by OS.

For example, you can't set up an IIS Application Pool on Windows 2000, which does not run IIS 6, but you still want to install web applications and manage a similar IIS tree.

Here is a function that returns an OS indicator. You can query a remote machine's OS, provided you have administrative access. To query the local machine, use "." for the machine argument.

'***************************************************************
' Get System OS from a Remote Machine
'***************************************************************
Function GetOS_Remote(strMachine)
'WMI is required for this script to function

Dim strComputer, strWMIOS

Dim objWmiService : Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strMachine &
"\root\cimv2")

Dim strOsQuery : strOsQuery = "Select * from
Win32_OperatingSystem"

Dim colOperatingSystems : Set colOperatingSystems =
objWMIService.ExecQuery(strOsQuery)

Dim objOs

Dim strOsVer
For Each objOs in colOperatingSystems

strWmios = objOs.Caption & " " & objOs.Version

Next

Select Case True

'Add more info to the 98 and 95 to get the specific version. i.e. 98SE 95 a,b,or c

Case InStr(strWmiOS, "2000 Server") > 1 : GetOS_Remote = "2KSRV"

Case InStr(strWmiOS, "2003, Standard") > 1 : GetOS_Remote = "2K3SRV"

Case InStr(strWmiOS, "2003, Enterprise") > 1 : GetOS_Remote = "2K3ENTSRV"

Case InStr(strWmiOS, "2000 Advanced Server") > 1 : GetOS_Remote = "2KADVSRV"

Case InStr(strWmiOS, "Windows NT") > 1 : GetOS_Remote = "NT4"

Case InStr(strWmiOS, "Windows 2000") > 1 : GetOS_Remote = "W2K"

Case InStr(strWmiOS, "Windows XP") > 1 : GetOS_Remote = "WXP"

Case Else : GetOS_Remote = "Unknown"

End Select

End Function


2 comments:

Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.
Oes Tsetnoc | Semangat Mengembalikan Jati Diri Bangsa

Anonymous said...

Can anyone recommend the well-priced Remote Management & Monitoring software for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central endpoint protection
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!