Thursday, 17 March 2011

Appsense Re-useable Conditions for OS Version and Architecture

The following are handy Custom Conditions that can be used to detect OS Version (2003 or 2008) and also the architecure type (32 bit or 64 bit)

Adding these as Re-usable conditions will allow you to use this throughout the EM configuration to ensure the correct deployment of settings.

The scripts below use WMI to detect the version information. It is also possible to use Registry reads to detect the windows version. I am blogging those keys in a seperate article

32 BIT OS DETECTION
Option Explicit
WScript.Quit(OSArch("x86") + 1)
Function OSArch(lookfor)
Dim objShell, strArch
Set objShell = WScript.CreateObject("WScript.Shell")
strArch = objShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")
If LCase(strArch) = LCase(lookfor) Then OSArch = True Else OSArch = False
End Function

64 BIT OS DETECTION
Option Explicit
WScript.Quit(OSArch("amd64") + 1)
Function OSArch(lookfor)
Dim objShell, strArch
Set objShell = WScript.CreateObject("WScript.Shell")
strArch = objShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")
If LCase(strArch) = LCase(lookfor) Then OSArch = True Else OSArch = False
End Function

DETECT SERVER 2003
'Get the WMI object and query results
Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMI.ExecQuery("Select Version from Win32_OperatingSystem",,48)

For Each item In colItems
OSVersion = item.Version
Next

If Left(OSVersion, 3) = "5.2" Then
Wscript.Quit 0 'success
Else
Wscript.Quit 1 'failure
End If

DETECT SERVER 2008
'Get the WMI object and query results
Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMI.ExecQuery("Select Version from Win32_OperatingSystem",,48)

For Each item In colItems
OSVersion = item.Version
Next

If Left(OSVersion, 3) = "6.0" Then
Wscript.Quit 0 'success
Else
Wscript.Quit 1 'failure
End If

No comments:

Post a Comment