Skip to content

Detecting OS in VBS

Featured Replies

Hi Guys,

I got some code that i need to extend to include detection of vista windows 7 2008 etc and was wondering if anyone could give me some assistance.

 

basically i need to add detection of windows vista and 7 and possibly w2k8+ ....any ideas...have nfi btw... looking at snippets atm trying to solve....

 

'==========================================================================
'Determine OS using WMI
'==========================================================================
Dim sWXPP, sW2KP, sW2KS, sW2KAS, sW2KDS, sW2K3S, sW2K3W, sW2K3E, sUnkOS, sWbemOpSys
Dim oWbemServices
Dim cOperatingSystems
Dim oInstance

sWXPP = "Microsoft Windows XP Professional"
sW2KP = "Microsoft Windows 2000 Professional"
sW2KS = "Microsoft Windows 2000 Server"
sW2KAS = "Microsoft Windows 2000 Advanced Server"
sW2KDS = "Microsoft Windows 2000 Datacenter Server"
sW2K3S = "Microsoft(R) Windows(R) Server 2003, Standard Edition"
sW2K3W = "Microsoft(R) Windows(R) Server 2003, Web Edition"
sW2K3E = "Microsoft(R) Windows(R) Server 2003, Enterprise Edition"
sUnkOS = "OS Unknown or NOT supported"

Set oWbemServices = GetObject("winmgmts:")
Set cOperatingSystems = oWbemServices.InstancesOf("Win32_OperatingSystem")
On Error Resume Next
For Each oInstance in cOperatingSystems
 sWbemOpSys = oInstance.Caption
 If sWbemOpSys = "" Then
   sWbemOpSys = sUnkOS
 End If
Next

Select Case sWbemOpSys
 Case sWXPP
 Case sW2KP
 Case sW2KS
 Case sW2KAS
 Case sW2KDS
 Case sW2K3S
 Case sW2K3W
 Case sW2K3E
 Case Else
   sContent = sFJImg & "<h3><center>OS Not Supported:" _
            & "<br><br>" & sWbemOpSys & "</center></h3>"
   oDialogWindow.document.body.innerHTML = sContent
   WScript.Sleep 1000

   oDialogWindow.Quit
   WScript.Quit
End Select

  • 1 month later...

Hi Guys,

I got some code that i need to extend to include detection of vista windows 7 2008 etc and was wondering if anyone could give me some assistance.

 

basically i need to add detection of windows vista and 7 and possibly w2k8+ ....any ideas...have nfi btw... looking at snippets atm trying to solve....

 

'==========================================================================
'Determine OS using WMI
'==========================================================================
Dim sWXPP, sW2KP, sW2KS, sW2KAS, sW2KDS, sW2K3S, sW2K3W, sW2K3E, sUnkOS, sWbemOpSys
Dim oWbemServices
Dim cOperatingSystems
Dim oInstance

sWXPP = "Microsoft Windows XP Professional"
sW2KP = "Microsoft Windows 2000 Professional"
sW2KS = "Microsoft Windows 2000 Server"
sW2KAS = "Microsoft Windows 2000 Advanced Server"
sW2KDS = "Microsoft Windows 2000 Datacenter Server"
sW2K3S = "Microsoft(R) Windows(R) Server 2003, Standard Edition"
sW2K3W = "Microsoft(R) Windows(R) Server 2003, Web Edition"
sW2K3E = "Microsoft(R) Windows(R) Server 2003, Enterprise Edition"
sUnkOS = "OS Unknown or NOT supported"

Set oWbemServices = GetObject("winmgmts:")
Set cOperatingSystems = oWbemServices.InstancesOf("Win32_OperatingSystem")
On Error Resume Next
For Each oInstance in cOperatingSystems
 sWbemOpSys = oInstance.Caption
 If sWbemOpSys = "" Then
   sWbemOpSys = sUnkOS
 End If
Next

Select Case sWbemOpSys
 Case sWXPP
 Case sW2KP
 Case sW2KS
 Case sW2KAS
 Case sW2KDS
 Case sW2K3S
 Case sW2K3W
 Case sW2K3E
 Case Else
   sContent = sFJImg & "<h3><center>OS Not Supported:" _
		& "

" & sWbemOpSys & "</center></h3>"
   oDialogWindow.document.body.innerHTML = sContent
   WScript.Sleep 1000

   oDialogWindow.Quit
   WScript.Quit
End Select

 

So basically this is just to filter out systems that aren't running one of the prescribed OS's, correct?

 

In this case, you just need to add the identifiers for Windows 7 (and every other OS you want to detect) as cases to your select statement.

 

Specifically, you'll need to add a short variable for each string to be added, and then throw a case for each short variable into your select statement.

 

I don't know what versions of Vista, 7, and 2008 you'll be using (home, home premium, ultimate, standard, datacenter, etc.), but I'll assume you only need to detect Windows 7 Ultimate for my example...

 


sWXPP = "Microsoft Windows XP Professional"
sW2KP = "Microsoft Windows 2000 Professional"
sW2KS = "Microsoft Windows 2000 Server"
sW2KAS = "Microsoft Windows 2000 Advanced Server"
sW2KDS = "Microsoft Windows 2000 Datacenter Server"
sW2K3S = "Microsoft(R) Windows(R) Server 2003, Standard Edition"
sW2K3W = "Microsoft(R) Windows(R) Server 2003, Web Edition"
sW2K3E = "Microsoft(R) Windows(R) Server 2003, Enterprise Edition"
sW7U = "Microsoft Windows 7 Ultimate "                                                	<============== Defining the short variable
sUnkOS = "OS Unknown or NOT supported"
.
.
.
Select Case sWbemOpSys
 Case sWXPP
 Case sW2KP
 Case sW2KS
 Case sW2KAS
 Case sW2KDS
 Case sW2K3S
 Case sW2K3W
 Case sW2K3E
 Case sW7U                                                                  		<============== Set the case where sWbemOpSys==sW7U
 Case Else
   sContent = sFJImg & "<h3><center>OS Not Supported:" _
		& "

" & sWbemOpSys & "</center></h3>"
   oDialogWindow.document.body.innerHTML = sContent
   WScript.Sleep 1000

   oDialogWindow.Quit
   WScript.Quit
End Select

 

You'll need to add additional lines like the ones above for each OS you need to detect. To find the strings on each OS you might consider using a tool called WMICodeCreator ( http://www.microsoft...&displaylang=en ). It is a handy tool, from Microsoft, that allows you to browse WMI, and even create VBscript code from the selections you have made in the GUI. It is pretty straight forward to use. You'll want to run WMICodeCreator on each OS you want to collect, and get the Caption value from the Win32_OperatingSystem class.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.