如何在VBScript中不使用WMI查找操作系统名称?

时间:2012-08-12 14:20:52

标签: vbscript

我需要一种方法来查找操作系统版本而不使用winmgmts。我需要一种独立于平台的方法来查找OS,vista,win7等的名称。

5 个答案:

答案 0 :(得分:3)

我们必须解析在2K / XP上不同的用户帐户中的路径,然后它们在Vista / Win7上。 comspec返回如下所示:Microsoft Windows [Version 6.1.7600]。 2k / XP是版本5.x,Vista / Win7是版本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`

答案 1 :(得分:1)

的VBScript:

Set oShell = CreateObject( "WScript.Shell" )
os_name=oShell.ExpandEnvironmentStrings("%OS%")
WScript.Echo os_name

答案 2 :(得分:0)

来自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 

答案 3 :(得分:0)

这个page提供了几个用于获取常规Windows操作系统信息的包装程序,所有这些都使用对GetVersionEx API的单次调用。

GetVersionEx: Windows Version, Service Pack and Platform Info

答案 4 :(得分:0)

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