用 VBS 判斷 32 or 64bit OS
  • 5,696 views,
  • 2014-09-01,
  • 上傳者: 洪國恩,
  •  0
c3e56b0a70ef189227ee305b474c29ec.jpg如果要快速的判斷 OS 是 32 or 64 位元的,可以簡單使用 VBScript 喔. 如果是要在其他程式,那就透過 WMI 的方式去取得吧!
 
以下的範例可以判斷 CPU 跟 OS 為 32 or 64 Bits,並且在以下平台驗證過囉~ 
 
Windows Server 2012 沒有
Windows Server 2008 R2
Windows Server 2008
Windows Server 2003
Windows 8 沒有
Windows 7
Windows Vista
Windows XP
Windows 2000
 
 
Option Explicit 
 
Dim ObjWMI, ColSettings, ObjProcessor 
Dim StrComputer, ObjNetwork 
 
Set ObjNetwork = WScript.CreateObject("WScript.Network") 
StrComputer = Trim(ObjNetwork.ComputerName) 
Set ObjNetwork = Nothing 
WScript.Echo VbCrLf & "Computer Name: " & StrComputer 
WScript.Echo vbNullString 
Set ObjWMI = GetObject("WINMGMTS:" & "{ImpersonationLevel=Impersonate,AuthenticationLevel=Pkt}!\\" & StrComputer & "\Root\CIMV2") 
Set ColSettings = ObjWMI.ExecQuery ("SELECT * FROM Win32_Processor") 
For Each ObjProcessor In ColSettings 
    Select Case ObjProcessor.Architecture 
        Case 0 
            WScript.Echo "Processor Architecture Used by the Platform: x86" 
        Case 6 
            WScript.Echo "Processor Architecture Used by the Platform: Itanium-Based System" 
        Case 9 
            WScript.Echo "Processor Architecture Used by the Platform: x64" 
    End Select 
    Select Case ObjProcessor.ProcessorType 
        Case 1 
            WScript.Echo "Processor Type: Other. Not in the Known List"     
        Case 2 
            WScript.Echo "Processor Type: Unknown Type" 
        Case 3 
            WScript.Echo "Processor Type: Central Processor (CPU)" 
        Case 4 
            WScript.Echo "Processor Type: Math Processor" 
        Case 5 
            WScript.Echo "Processor Type: DSP Processor" 
        Case 6 
            WScript.Echo "Processor Type: Video Processor" 
    End Select 
    WScript.Echo "Processor: " & ObjProcessor.DataWidth & "-Bit" 
    WScript.Echo "Operating System: " & ObjProcessor.AddressWidth & "-Bit" 
    WScript.Echo vbNullString     
    If ObjProcessor.Architecture = 0 AND ObjProcessor.AddressWidth = 32 Then 
        WScript.Echo "This Machine has 32 Bit Processor and Running 32 Bit OS" 
    End If 
    If (ObjProcessor.Architecture = 6 OR ObjProcessor.Architecture = 9) AND ObjProcessor.DataWidth = 64 AND ObjProcessor.AddressWidth = 32 Then 
        WScript.Echo "This Machine has 64-Bit Processor and Running 32-Bit OS" 
    End If 
    If (ObjProcessor.Architecture = 6 OR ObjProcessor.Architecture = 9) AND ObjProcessor.DataWidth = 64 AND ObjProcessor.AddressWidth = 64 Then 
        WScript.Echo "This Machine has 64-Bit Processor and Running 64-Bit OS" 
    End If 
Next 
Set ObjProcessor = Nothing:    Set ColSettings = Nothing:    Set ObjWMI = Nothing:    StrComputer = vbNullstring
Facebook 討論區載入中...
資料夾 :
發表時間 :
2014-09-01 15:25:09
觀看數 :
5,696
發表人 :
洪國恩
部門 :
老洪的 IT 學習系統
QR Code :