2009-02-17 10 views

Respuesta

3

No estoy seguro de que necesite comprobar si el script se está ejecutando en x64.

Intente leer desde HKLM\Software\Wow6432Node\xyz, si eso falla, intente leer desde HKLM\Software\xyz, si eso falla, su clave de registro no existe, realice las acciones apropiadas.

Por supuesto, si su diseño es más complicado (por ejemplo, escribe un valor en esa clave de registro si no existe), entonces esa sugerencia no funcionará.

Aquí hay un VBScript para examinar el sistema operativo. Es posible que también necesita explicación de la Properties available from the Win32_OperatingSystem Class

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

Set colOperatingSystems = objWMIService.ExecQuery _ 
    ("Select * from Win32_OperatingSystem") 

For Each objOperatingSystem in colOperatingSystems 
    msg = objOperatingSystem.Caption & " " & _ 
      objOperatingSystem.Version & " " & _ 
       objOperatingSystem.OSArchitecture 
    msgbox msg 
Next 

Tenga en cuenta que para Windows XP y 2003, OSArchitecture no está disponible, en cuyo caso es probable que tenga a examinar ya sea la CaptionVersion o para determinar si su sistema operativo es 64 bits

También podría usar algo como this dependiendo del nivel de complejidad que requiera.

+0

Estoy leyendo desde una tecla específica, por lo que la prueba de lectura desde el nodo en Wow6432Node es suficiente. ¡Gracias! – vividos

1

No mencionó qué API utiliza para leer en el registro. Por ejemplo, si utiliza la clase WMI StdRegProv, puede usar el indicador __ProviderArchitecture para solicitar acceso al segmento de registro de 32 bits, independientemente de si el script se ejecuta en Windows Script Host de 32 bits o 64 bits. Esta técnica se describe en el artículo Requesting WMI Data on a 64-bit Platform en MSDN.

He aquí un ejemplo de la lectura del registro de 32 bits:

strComputer = "." 
Const HKLM = &h80000002 

''# Specify the required registry bitness 
Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet") 
oCtx.Add "__ProviderArchitecture", 32 
oCtx.Add "__RequiredArchitecture", True 

''# Load the 32-bit registry provider 
Set oLocator = CreateObject("WbemScripting.SWbemLocator") 
Set oWMI = oLocator.ConnectServer(strComputer, "root\default",,,,,, oCtx) 
Set oReg = oWMI.Get("StdRegProv") 

''# Specify input parameters for the GetStringValue method call 
Set oInParams = oReg.Methods_("GetStringValue").InParameters 
oInParams.hDefKey  = HKLM 
oInParams.sSubKeyName = "Software\xyz" 
oInParams.sValueName = "foobar" 

''# Read a string value from the registry 
Set oOutParams = oReg.ExecMethod_("GetStringValue", oInParams,, oCtx) 
WScript.Echo oOutParams.sValue 

Tenga en cuenta también, que en este caso los nombres clave de 32 bits deben especificarse de manera habitual como HKLM\Software\xyz en lugar de HKLM\Software\Wow6432Node\xyz.

4

Incluso en la versión de 64 bits de Windows, su script puede ejecutarse en modo de 32 bits.

Puede utilizar siguiente código para determinar el modo de bits real, script que corre en:

option explicit 

function Determine64BitMode 
    dim Shell, Is64BitOs 
    set Shell = CreateObject("WScript.Shell") 
    on error resume next 
    Shell.RegRead "HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir (x86)" 
    Is64BitOs = Err.Number = 0 
    on error goto 0 
    if Is64BitOs then 
     Determine64BitMode = InStr(Shell.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir"), "(x86)") = 0 
    else 
     Determine64BitMode = false 
    end if 
end function 

dim ExecutingIn64BitMode 
ExecutingIn64BitMode = Determine64BitMode 
if ExecutingIn64BitMode then 
    MsgBox "64 bit" 
else 
    MsgBox "32 bit" 
end if 
1

Aquí es una solución basada en la base de conocimientos artículo de Microsoft How To Check If Computer Is Running A 32 Bit or 64 Bit Operating System:

Function Is64BitOS() 
    Is64BitOS = Not(Is32BitOS()) 
End Function 

Function Is32BitOS() 
    Const sRegKey = "HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0" 
    Const sIdentifierValue = "Identifier" 
    Const sPlatformIDValue = "Platform ID" 

    Dim oSh : Set oSh = CreateObject("WScript.Shell") 
    Dim sIdentifier, nPlatformID 

    sIdentifier = oSh.RegRead(sRegKey & "\" & sIdentifierValue) 
    nPlatformID = oSh.RegRead(sRegKey & "\" & sPlatformIDValue) 

    Set oSh = Nothing 

    If InStr(sIdentifier, "x86") > 0 And nPlatformID = 32 Then 
     Is32BitOS = True 
    Else 
     Is32BitOS = False 
    End if 
End Function 

SOLUCIÓN ALTERNATIVA

Una solución alternativa y más concisa que hace uso de WMI se puede encontrar here.

0

Esta muestra tanto el sistema y el proceso arquitecturas:

Option Explicit 
Dim WshShell, WshEnv 
Set WshShell = WScript.CreateObject("WScript.Shell") 
Set WshEnv = WshShell.Environment("System") 
MsgBox "System: " & WshEnv("PROCESSOR_ARCHITECTURE") 
Set WshEnv = WshShell.Environment("Process") 
MsgBox "Process: " & WshEnv("PROCESSOR_ARCHITECTURE") 

Sólo echa el que necesita para <> "x86".

Cuestiones relacionadas