在VBScript中拉远程Windows服务器体系结构

时间:2012-08-08 13:46:47

标签: vbscript wmi

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

  

WshShell.RegRead:注册表项中的root无效   “\ * remotesystem * \ HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentCon   trolSet \ 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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

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

检查此样本

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