0

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

4

5 回答 5

3

我们必须解析在 2K/XP 上与 Vista/Win7 上不同的用户帐户中的路径。comspec 返回如下所示:Microsoft Windows [版本 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`
于 2012-08-12T18:31:52.353 回答
1

脚本:

Set oShell = CreateObject( "WScript.Shell" )
os_name=oShell.ExpandEnvironmentStrings("%OS%")
WScript.Echo os_name
于 2012-08-12T14:31:33.513 回答
0

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

GetVersionEx:Windows 版本、服务包和平台信息

于 2012-08-12T21:27:21.477 回答
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 
于 2012-08-12T15:28:28.003 回答
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
于 2014-01-17T13:07:23.427 回答