Jump to content


  • 0
jamitupya

Detecting OS in VBS

Question

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

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

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.

Share this post


Link to post
Share on other sites

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.