1

我有以下代码。我正在尝试获取有关我要连接的远程计算机是 32 位还是 64 位的信息。我尝试在此代码的最后一个片段中执行此操作,但没有成功。这是错误(我更改了远程系统名称):

WshShell.RegRead:注册表项“\*remotesystem*\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE”中的根无效。

Option Explicit

Dim objWMISrvc,strRemoteComputer,colOSItems,objItem,args,OsType

'String variables
Dim strName,strCaption,strVersion,strCSDVer,strSerial,WshShell

'Adding this in to transfer FQDN variable to this script from ASP.net
Set args = WScript.Arguments
strRemoteComputer = args.Item(0)

Set objWMISrvc = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strRemoteComputer & "\root\cimv2")


CheckOSType objWMISrvc


Sub CheckOSType( objWMISrvc )
        Set colOSItems = objWMISrvc.ExecQuery("Select * from Win32_OperatingSystem",,48)
        For Each objItem in colOSItems
            strName = objItem.CSName 
            'strDesc = objItem.Description 
            'strManufac = objItem.Manufacturer 
            strCaption = objItem.Caption 
            strVersion = objItem.Version 
            strCSDVer = objItem.CSDVersion 
            strSerial = objItem.SerialNumber 
        Next


        Set WshShell = CreateObject("WScript.Shell")
        OsType = WshShell.RegRead("\\" & strRemoteComputer & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
        If OsType = "x86" then
            WScript.Echo "Windows 32bit system detected"
        elseif OsType = "AMD64" then
            WScript.Echo "Windows 64bit system detected"
        end if

End Sub
4

2 回答 2

3

您可以直接从 WMI 执行此操作,而无需读取注册表。只需使用此脚本遍历您的计算机名称。它返回“32”或“64”。

strComputer = "."

Set objWMIService = GetObject("winmgmt:\\" & strComputer & "\root\cimv2")

Set colProcessors = objWMIService.ExecQuery("Select * from Win32_Processor")

For Each objProcessor in colProcessors
    WScript.Echo objProcessor.AddressWidth     'or  objProcessor.DataWidth
    Exit For
Next
于 2012-08-08T17:10:42.867 回答
1

要读取远程计算机的注册表,您必须使用StdRegProvWMI 类

检查这个样本

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject( _
   "winmgmts:{impersonationLevel=impersonate}!\\" &_
    strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
strValueName = "PROCESSOR_ARCHITECTURE"
oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,OsType
WScript.Echo  OsType
于 2012-08-08T16:41:18.087 回答