Reputation: 181
I need a way to find the operating system version without using winmgmts. I need a platform independent way of find the name of the OS, vista, win7, etc.
Upvotes: 0
Views: 21582
Reputation: 11
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each os in oss
Wscript.Echo "Caption: " & os.Caption
Wscript.Echo "Code Set: " & os.CodeSet
Wscript.Echo "Country Code: " & os.CountryCode
Wscript.Echo "Debug: " & os.Debug
Wscript.Echo "Encryption Level: " & os.EncryptionLevel
dtmConvertedDate.Value = os.InstallDate
dtmInstallDate = dtmConvertedDate.GetVarDate
Wscript.Echo "Install Date: " & dtmInstallDate
Wscript.Echo "Licensed Users: " & os.NumberOfLicensedUsers
Wscript.Echo "Organization: " & os.Organization
Wscript.Echo "OS Language: " & os.OSLanguage
Wscript.Echo "OS Product Suite: " & os.OSProductSuite
Wscript.Echo "OS Type: " & os.OSType
Wscript.Echo "Primary: " & os.Primary
Wscript.Echo "Serial Number: " & os.SerialNumber
Wscript.Echo "Version: " & os.Version
Next
Upvotes: 1
Reputation: 16368
From VisualBasicScript.com:
Option Explicit
Dim oShell
Dim oShellExec, oStdOutputText, sText, iElement, aOS, sOS
Set oShell = CreateObject("Wscript.Shell")
Set oShellExec = oShell.Exec("%comspec% /c ver")
Set oStdOutputText = oShellExec.StdOut
Do While Not oStdOutputText.AtEndOfStream
sText = oStdOutputText.ReadLine
aOS = Array("Windows 95", "Windows 98", "Windows NT", "Windows 2000", "Windows XP", "Microsoft Windows [Version")
For iElement = LBound(aOS) To UBound(aOS)
If InStr(sText, aOS(iElement)) <> 0 Then
If aOS(iElement) = "Microsoft Windows [Version" Then
If InStr(sText, "Version6.0") <> 0 Then
sOS = "Windows Vista"
ElseIf InStr(sText, "Version 6.1")<>0 Then
sOS = "Windows 7"
Else
sOS = "Windows 2003"
End If
Else
sOS = aOS(iElement)
End If
End If
Next
Loop
WScript.Echo sOS
Upvotes: 0
Reputation: 8131
This page provides several wrapper routines for obtaining general Windows operation system information, all using a single call to the GetVersionEx API.
Upvotes: 0
Reputation: 181
We have to parse paths in user accounts that are different on 2K/XP then they are on Vista / Win7. The comspec return looks like this: Microsoft Windows [Version 6.1.7600]. 2k/XP is Version 5.x and Vista/Win7 is Version 6.x.
Set shell = CreateObject("WScript.Shell")
Set getOSVersion = shell.exec("%comspec% /c ver")
version = getOSVersion.stdout.readall
wscript.echo version
Select Case True
Case InStr(version, "n 5.") > 1 : GetOS = "XP"
Case InStr(version, "n 6.") > 1 : GetOS = "Vista"
Case Else : GetOS = "Unknown"
End Select
wscript.echo GetOS`
Upvotes: 3
Reputation: 8131
VBscript:
Set oShell = CreateObject( "WScript.Shell" )
os_name=oShell.ExpandEnvironmentStrings("%OS%")
WScript.Echo os_name
Upvotes: 1