2012-08-12 63 views

回答

1

的VBScript:

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

該解決方案將返回Windows_NT爲WinXP中,Vista中,和Win7。我需要區分不同版本的NT。 – toddstavish 2012-08-12 17:53:59

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 
+0

這不區分XP和Vista/Win7,在Win7上這返回Windows 2003 – toddstavish 2012-08-12 18:35:44

+0

@toddstavish:已修復支持Vista和Windows 7. – 2012-08-13 23:37:15

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` 
+0

謝謝! :)我使用了case語句的修改版本,但是使用WMI對象獲得了版本號:'Set oWMI = GetObject(「winmgmts:\\。\ root \ cimv2」)'...和:'Set rows = oWMI.ExecQuery(「從Win32_OperatingSystem選擇版本」,48)'...接着循環「行」(僅1)以獲取版本。 – Chiramisu 2014-08-23 01:33:05

0

page提供了獲得通用的Windows操作系統的信息,所有使用該GetVersionEx API的單一調用幾個包裝程序。

GetVersionEx: Windows Version, Service Pack and Platform Info

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 
相關問題