Login | |
|
 |
Re: OS detection - 5/14/2005 12:55:54 AM
|
|
 |
|
| |
TNO
Posts: 1303
Score: 12
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
Maybe this will work for you: SetLocale "en-us" ' do not remove iOSVer = GetOsVersionNumber() Function GetOsVersionNumber() ''''''''''''''''''''''''''''''í''''''''''''''''''''''''''''''í'''''' ' Determines OS by reading reg val & comparing to known values ' OS version number returned as number of type double: ' Windows 95: 1 ' Windows 98: 2 ' Windows ME: 3 ' Windows NT4: 4 ' Windows 2k: 5 ' Windows XP: 5.1 ' Windows Server 2003: 5.2 ' Windows x: >5.2 ' ''''''''''''''''''''''''''''''í''''''''''''''''''''''''''''''í'''''' Dim oShell, sOStype, sOSversion Set oShell = CreateObject("Wscript.Shell") On Error Resume Next sOStype = oShell.RegRead(_ "HKLM\SYSTEM\CurrentControlSetí\Control\ProductOptions\ProducítType") If Err.Number<>0 Then ' Hex(Err.Number)="80070002" ' - Could not find this key, OS must be Win9x Err.Clear sOStype = oShell.RegRead(_ "HKLM\SOFTWARE\Microsoft\Windoíws" & _ "\CurrentVersion\VersionNumberí") Select Case sOStype Case "4.00.950" sOSversion = 1 ' Windows 95A Case "4.00.1111" Dim sSubVersion sSubVersion = oShell.RegRead(_ "HKLM\SOFTWARE\Microsoft\Windoíws" & _ "\CurrentVersion\SubVersionNumíber") Select Case sSubVersion Case " B" sOSversion = 1 ' Windows 95B Case " C" sOSversion = 1 ' Windows 95C Case Else sOSversion = 1 ' Unknown Windows 95 End Select Case "4.03.1214" sOSversion = 1 ' Windows 95B Case "4.10.1998" sOSversion = 2 ' Windows 98 Case "4.10.2222" sOSversion = 2 ' Windows 98SE Case "4.90.3000" sOSversion = 3 ' Windows Me Case Else sOSversion = 1 ' Unknown W9x/Me End Select Else ' OS is NT based sOSversion = oShell.RegRead(_ "HKLM\SOFTWARE\Microsoft\Windoíws NT\CurrentVersion\CurrentVersiíon") If Err.Number<>0 Then GetOsVersion = "Unknown NTx" ' Could not determine NT version Exit Function ' >>> End If End If ' Setting Locale to "en-us" to be indifferent to country settings. ' CDbl might err else SetLocale "en-us" GetOsVersionNumber = CDbl(sOSversion) End Function wscript.echo GetOsVersionNumber
|
|
| |
|
|
|
 |
Re: OS detection - 5/14/2005 3:42:38 PM
|
|
 |
|
| |
TNO
Posts: 1303
Score: 12
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
StdOut.ReadAll Excellent, I never knew that.
|
|
| |
|
|
|
 |
Re: OS detection - 5/16/2005 12:01:55 AM
|
|
 |
|
| |
mbouchard
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
I use have created a function, 3 to be exact, that will find the OS. 1 uses WMI while the other 2 use ver, 1 with exec and the other writing to and reading from a txt file. Option Explicit msgbox GetOS1 msgbox GetOS2 msgbox GetOS3 Function GetOS1() 'Will work with most versions of WSH. Const OpenAsASCII = 0 Const FailIfNotExist = 0 Const ForReading = 1 Dim WshShell : Set WshShell = CreateObject("WScript.Shell") Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject") Dim sTemp, sTempFile, fFile, sResults sTemp = WshShell.ExpandEnvironmentStrings("%TEMP%") sTempFile = sTemp & "\runresult.tmp" WshShell.Run "%comspec% /c ver >" & sTempFile, 0, True Set fFile = FSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII) sResults = fFile.ReadAll fFile.Close FSO.DeleteFile(sTempFile) 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(sResults, "Windows 95") > 1 : GetOS1 = "W95" Case InStr(sResults, "Windows 98") > 1 : GetOS1 = "W98" Case InStr(sResults, "Windows Millennium") > 1 : GetOS1 = "WME" Case InStr(sResults, "Windows NT") > 1 : GetOS1 = "NT4" Case InStr(sResults, "Windows 2000") > 1 : GetOS1 = "W2K" Case InStr(sResults, "Windows XP") > 1 : GetOS1 = "WXP" Case Else : GetOS1 = "Unknown" End Select End Function Function GetOS2() 'Requires WSH 5.6 Dim WshShell : Set WshShell = CreateObject("WScript.Shell") Dim strVer : set strVer = WshShell.exec("%comspec% /c ver") Dim sResults sResults = strVer.stdout.readall 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(sResults, "Windows 95") > 1 : GetOS2 = "W95" Case InStr(sResults, "Windows 98") > 1 : GetOS2 = "W98" Case InStr(sResults, "Windows Millennium") > 1 : GetOS2 = "WME" Case InStr(sResults, "Windows NT") > 1 : GetOS2 = "NT4" Case InStr(sResults, "Windows 2000") > 1 : GetOS2 = "W2K" Case InStr(sResults, "Windows XP") > 1 : GetOS2 = "WXP" Case Else : GetOS2 = "Unknown" End Select End Function Function GetOS3 'WMI is required for this script to function Dim strComputer, strWMIOS 'For Local use only, remove the inputbox and make strComputer = "." strComputer = Inputbox("Input the name of the remote computer or hit enter for this PC.") If strComputer = "" then strComputer = "." End if Dim objWmiService : Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"& strComputer & "\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 msgbox strWMIOS 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 : GetOS3 = "2KSRV" Case InStr(strWmiOS, "2003, Standard") > 1 : GetOS3 = "2K3SRV" Case InStr(strWmiOS, "2003, Enterprise") > 1 : GetOS3 = "2K3ENTSRV" Case InStr(strWmiOS, "2000 Advanced Server") > 1 : GetOS3 = "2KADVSRV" Case InStr(strWmiOS, "Windows NT") > 1 : GetOS3 = "NT4" Case InStr(strWmiOS, "Windows 2000") > 1 : GetOS3 = "W2K" Case InStr(strWmiOS, "Windows XP") > 1 : GetOS3 = "WXP" Case Else : GetOS3 = "Unknown" End Select End Function
< Message edited by mbouchard -- 8/29/2005 6:57:54 AM >
|
|
| |
|
|
|
 |
Re: OS detection - 5/16/2005 12:56:33 AM
|
|
 |
|
| |
mbouchard
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
Thanks
|
|
| |
|
|
|
 |
Re: OS detection - 5/16/2005 11:12:50 PM
|
|
 |
|
| |
mbouchard
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
I see one problem with the case statement quote: Case "Mi" GetOS = "Millenium" Case "Mi" GetOS = "2000"
With this, you will never get to 2000. It will be hit millenium then stop. The more information you have in your case the better chance you have of getting the correct OS. Which is one reason in my examples I use Windows xx. Also, you might want to make the returns "case insensitive" I.e. WinVers = Left(Ucase(winvers),22) that way you can always be certain something will be upper or lower case, which is something I need to do with my examples script, doing this in a production script though. This won't be a problem with the numbers but can help with the letters.
|
|
| |
|
|
|
 |
Re: OS detection - 5/18/2005 12:21:21 AM
|
|
 |
|
| |
mbouchard
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
Might I inquire why you are sticking with the reg? What issues are you experiencing with other ways of doing this?
|
|
| |
|
|
|
 |
Re: OS detection - 5/18/2005 1:49:01 AM
|
|
 |
|
| |
mbouchard
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
If all you are wanting to do is install WMI on pc's that need it, why not just check for the presence of WMI? systemfolder/WBEM/wbemcode.dll is the file you would look for. here is a script that should work on all os's Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") SysDir = fso.GetSpecialFolder(1).Path msgbox WMI if Fso.FileExists(sysDir & "\WBEM\wbemcore.dll") then msgbox "wmi version is : " & fso.GetFileVersion(sysDir & "\WBEM\wbemcode.dll") Else Msgbox "WMI is Not installed" End If 'Edit Note, fixed for code errors.
|
|
| |
|
|
|
|
|