Detectar si la versión actual de Windows es de 32 bits o 64 bits
Lo creas o no, mi instalador es tan antiguo que no tiene una opción para detectar la versión de 64 bits de Windows.
¿Hay una llamada DLL de Windows o (mejor aún) una variable de entorno que daría esa información para Windows XP y Windows Vista?
Una posible solución
Veo que Wikipedia afirma que la versión de 64 bits de Windows XP y Windows Vista tienen una variable de entorno única: %ProgramW6432%
, así que supongo que estaría vacía en 32 bits Windows.
Esta variable apunta al directorio Program Files
, que almacena todo el programa instalado de Windows y otros. El valor predeterminado en los sistemas en inglés es C:\Program Files
. En las ediciones de 64 bits de Windows (XP, 2003, Vista), también hay %ProgramFiles(x86)%
que por defecto es C:\Program Files (x86)
y %ProgramW6432%
que por defecto es C:\Program Files
. %ProgramFiles%
en sí depende de si el proceso que solicita la variable de entorno es en sí mismo de 32 bits o 64 bits (esto es causado por la redirección de Windows en Windows de 64 bits).
22 answers
Vea el script por lotes listado en Cómo Comprobar Si La Computadora Está Ejecutando Un Sistema Operativo De 32 O 64 Bits. También incluye instrucciones para verificar esto desde el Registro:
Puede usar la siguiente ubicación del registro para verificar si la computadora está ejecutando 32 o 64 bits del sistema operativo Windows:
HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0
Verá las siguientes entradas del registro en el panel derecho:
Identifier REG_SZ x86 Family 6 Model 14 Stepping 12
Platform ID REG_DWORD 0x00000020(32)
Los anteriores " x86 " y " 0x00000020 (32)" indican que el sistema operativo la versión es de 32 bits.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-15 15:33:16
Para comprobar si hay una versión de 64 bits de Windows en un cuadro de comandos, utilizo la siguiente plantilla:
Prueba.mtd:
@echo off
if defined ProgramFiles(x86) (
@echo yes
@echo Some 64-bit work
) else (
@echo no
@echo Some 32-bit work
)
ProgramFiles(x86)
es una variable de entorno definida automáticamente por cmd.exe (versiones de 32 bits y 64 bits) solo en máquinas Windows de 64 bits.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-16 02:37:48
Aquí hay un código Delphi para comprobar si su programa se está ejecutando en un sistema operativo de 64 bits:
function Is64BitOS: Boolean;
{$IFNDEF WIN64}
type
TIsWow64Process = function(Handle:THandle; var IsWow64 : BOOL) : BOOL; stdcall;
var
hKernel32 : Integer;
IsWow64Process : TIsWow64Process;
IsWow64 : BOOL;
{$ENDIF}
begin
{$IFDEF WIN64}
//We're a 64-bit application; obviously we're running on 64-bit Windows.
Result := True;
{$ELSE}
// We can check if the operating system is 64-bit by checking whether
// we are running under Wow64 (we are 32-bit code). We must check if this
// function is implemented before we call it, because some older 32-bit
// versions of kernel32.dll (eg. Windows 2000) don't know about it.
// See "IsWow64Process", http://msdn.microsoft.com/en-us/library/ms684139.aspx
Result := False;
hKernel32 := LoadLibrary('kernel32.dll');
if hKernel32 = 0 then RaiseLastOSError;
try
@IsWow64Process := GetProcAddress(hkernel32, 'IsWow64Process');
if Assigned(IsWow64Process) then begin
if (IsWow64Process(GetCurrentProcess, IsWow64)) then begin
Result := IsWow64;
end
else RaiseLastOSError;
end;
finally
FreeLibrary(hKernel32);
end;
{$ENDIf}
end;
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-18 18:49:37
Probé la solución que sugerí en mi pregunta:
Probado para la variable de entorno Windows: ProgramW6432
Si no está vacío, entonces es Windows de 64 bits.W
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-03-18 13:25:12
De un script por lotes:
IF PROCESSOR_ARCHITECTURE == x86 AND
PROCESSOR_ARCHITEW6432 NOT DEFINED THEN
// OS is 32bit
ELSE
// OS is 64bit
END IF
Usando Windows API :
if (GetSystemWow64Directory(Directory, MaxDirectory) > 0)
// OS is 64bit
else
// OS is 32bit
Fuentes:
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-16 02:41:03
Si puede realizar llamadas a la API, intente usar GetProcAddress / GetModuleHandle para comprobar la existencia de IsWow64Process que solo está presente en el sistema operativo Windows que tiene versiones de 64 bits.
También podría probar la variable de entorno ProgramFiles(x86) utilizada en Vista/2008 para compatibilidad con versiones anteriores, pero no estoy 100% seguro sobre XP-64 o 2003-64.
¡Buena suerte!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-03-02 02:40:30
Utilicé esto dentro de un script de inicio de sesión para detectar Windows de 64 bits
If "% ProgramW6432% " = = "%ProgramFiles%" goto is64flag
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-03-04 23:29:40
Para un VBScript / WMI one-liner que recupera el número de bits reales (32 o 64) del sistema operativo o el Hardware, eche un vistazo a http://csi-windows.com/toolkit/csi-getosbits
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-14 14:39:27
No se que idioma está usando, pero . NET tiene la variable de entorno PROCESSOR_ARCHITEW6432
si el sistema operativo es de 64 bits.
Si todo lo que desea saber es si su aplicación está ejecutando 32 bits o 64 bits, puede comprobar IntPtr.Size
. Será 4 si se ejecuta en modo de 32 bits y 8 si se ejecuta en modo de 64 bits.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-16 02:28:15
Quiero añadir lo que uso en los scripts de shell (pero se puede usar fácilmente en cualquier idioma) aquí. La razón es que algunas de las soluciones aquí no funcionan con un WoW64, algunas usan cosas que realmente no están hechas para eso (comprobando si hay una carpeta *(x86)) o no funcionan en scripts cmd. Siento que esta es la forma" adecuada " de hacerlo, y debería ser segura incluso en futuras versiones de Windows.
@echo off
if /i %processor_architecture%==AMD64 GOTO AMD64
if /i %PROCESSOR_ARCHITEW6432%==AMD64 GOTO AMD64
rem only defined in WoW64 processes
if /i %processor_architecture%==x86 GOTO x86
GOTO ERR
:AMD64
rem do amd64 stuff
GOTO EXEC
:x86
rem do x86 stuff
GOTO EXEC
:EXEC
rem do arch independent stuff
GOTO END
:ERR
rem I feel there should always be a proper error-path!
@echo Unsupported architecture!
pause
:END
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-08 14:37:14
No se en que versión de Windows existe, pero en Windows Vista y posteriores esto se ejecuta:
Function Is64Bit As Boolean
Dim x64 As Boolean = System.Environment.Is64BitOperatingSystem
If x64 Then
Return true
Else
Return false
End If
End Function
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-16 02:39:22
Muchas respuestas mencionan llamar a IsWoW64Process()
o funciones relacionadas. Esta no es la manera correcta. Debe usar GetNativeSystemInfo()
que fue diseñado para este propósito. He aquí un ejemplo:
SYSTEM_INFO info;
GetNativeSystemInfo(&info);
if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
// It's a 64-bit OS
}
Véase también: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724340%28v=vs.85%29.aspx
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-24 04:42:49
En C#:
public bool Is64bit() {
return Marshal.SizeOf(typeof(IntPtr)) == 8;
}
{[2] {} En[5]}VB.NET:
Public Function Is64bit() As Boolean
If Marshal.SizeOf(GetType(IntPtr)) = 8 Then Return True
Return False
End Function
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-18 15:42:36
Yo uso esto:
@echo off
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
echo 64 BIT
) else (
echo 32 BIT
)
Funciona en Windows XP, lo probó en Windows XP Professional Tanto de 64 bits como de 32 bits.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-09 13:03:38
Sé que esto es antiguo pero, esto es lo que uso para detectar Win764
On Error Resume Next
Set objWSHShell = CreateObject("WScript.Shell")
strWinVer = objWSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\BuildLabEx")
If len(strWinVer) > 0 Then
arrWinVer = Split(strWinVer,".")
strWinVer = arrWinVer(2)
End If
Select Case strWinVer
Case "x86fre"
strWinVer = "Win7"
Case "amd64fre"
strWinVer = "Win7 64-bit"
Case Else
objWSHShell.Popup("OS Not Recognized")
WScript.Quit
End Select
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-01-19 21:43:33
Probé el siguiente archivo por lotes en Windows 7 x64/x86 y Windows XP x86 y está bien, pero no he probado Windows XP x64 todavía, pero esto probablemente funcionará:
If Defined ProgramW6432 (Do x64 stuff or end if you are aiming for x86) else (Do x86 stuff or end if you are aiming for x64)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-16 02:42:20
Usando Windows Powershell, si la siguiente expresión devuelve true, entonces es un sistema operativo de 64 bits:
(([Array](Get-WmiObject -Class Win32_Processor | Select-Object AddressWidth))[0].AddressWidth -eq 64)
Esto fue tomado y modificado de: http://depsharee.blogspot.com/2011/06/how-do-detect-operating-system.html (Método # 3). He probado esto en Win7 de 64 bits (en sesiones de PowerShell de 32 y 64 bits) y XP de 32 bits.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-29 21:23:20
La mejor manera es seguramente comprobar si hay dos directorios de archivos de programa, 'Archivos de programa' y ' Archivos de programa (x86)' La ventaja de este método es que puede hacerlo cuando el o / s no se está ejecutando, por ejemplo, si la máquina no se ha iniciado y desea volver a instalar el sistema operativo
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-04-25 07:42:47
Curiosamente, si utilizo
get-wmiobject -class Win32_Environment -filter "Name='PROCESSOR_ARCHITECTURE'"
Obtengo AMD64 tanto en ISE de 32 bits como de 64 bits (en Win7 de 64 bits).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-09 03:17:28
Otra forma creada por eGerman que usa números PE de ejecutables compilados (no se basa en registros de registro o variables de entorno):
@echo off &setlocal
call :getPETarget "%SystemRoot%\explorer.exe"
if "%=ExitCode%" EQU "00008664" (
echo x64
) else (
if "%=ExitCode%" EQU "0000014C" (
echo x32
) else (
echo undefined
)
)
goto :eof
:getPETarget FilePath
:: ~~~~~~~~~~~~~~~~~~~~~~
:: Errorlevel
:: 0 Success
:: 1 File Not Found
:: 2 Wrong Magic Number
:: 3 Out Of Scope
:: 4 No PE File
:: ~~~~~~~~~~~~~~~~~~~~~~
:: =ExitCode
:: CPU identifier
setlocal DisableDelayedExpansion
set "File=%~1"
set Cmp="%temp%\%random%.%random%.1KB"
set Dmp="%temp%\%random%.%random%.dmp"
REM write 1024 times 'A' into a temporary file
if exist "%File%" (
>%Cmp% (
for /l %%i in (1 1 32) do <nul set /p "=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
)
setlocal EnableDelayedExpansion
) else (endlocal &cmd /c exit 0 &exit /b 1)
REM generate a HEX dump of the executable file (first 1024 Bytes)
set "X=1"
>!Dmp! (
for /f "skip=1 tokens=1,2 delims=: " %%i in ('fc /b "!File!" !Cmp!^|findstr /vbi "FC:"') do (
set /a "Y=0x%%i"
for /l %%k in (!X! 1 !Y!) do echo 41
set /a "X=Y+2"
echo %%j
)
)
del !Cmp!
REM read certain values out of the HEX dump
set "err="
<!Dmp! (
set /p "A="
set /p "B="
REM magic number has to be "MZ"
if "!A!!B!" neq "4D5A" (set "err=2") else (
REM skip next 58 bytes
for /l %%i in (3 1 60) do set /p "="
REM bytes 61-64 contain the offset to the PE header in little endian order
set /p "C="
set /p "D="
set /p "E="
set /p "F="
REM check if the beginning of the PE header is part of the HEX dump
if 0x!F!!E!!D!!C! lss 1 (set "err=3") else (
if 0x!F!!E!!D!!C! gtr 1018 (set "err=3") else (
REM skip the offset to the PE header
for /l %%i in (65 1 0x!F!!E!!D!!C!) do set /p "="
REM next 4 bytes have to contain the signature of the PE header
set /p "G="
set /p "H="
set /p "I="
set /p "J="
REM next 2 bytes contain the CPU identifier in little endian order
set /p "K="
set /p "L="
)
)
)
)
del !Dmp!
if defined err (endlocal &endlocal &cmd /c exit 0 &exit /b %err%)
REM was the signature ("PE\0\0") of the PE header found
if "%G%%H%%I%%J%"=="50450000" (
REM calculate the decimal value of the CPU identifier
set /a "CPUID=0x%L%%K%"
) else (endlocal &endlocal &cmd /c exit 0 &exit /b 4)
endlocal &endlocal &cmd /c exit %CPUID% &exit /b 0
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-20 09:20:58
Aquí hay un método más simple para secuencias de comandos por lotes
@echo off
goto %PROCESSOR_ARCHITECTURE%
:AMD64
echo AMD64
goto :EOF
:x86
echo x86
goto :EOF
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-20 13:58:20
Compruebe en el Registro la existencia de HKLM \ SOFTWARE\Wow6432Node - Si está ahí, el sistema es de 64 bits - 32 bits, de lo contrario.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-04 15:36:05