This is all you need: Code: @ECHO OFF SETLOCAL SET xNN=x%PROCESSOR_ARCHITECTURE:~-2% IF %xNN% EQU x86 (IF DEFINED PROCESSOR_ARCHITEW6432 SET xNN=x64) ECHO( Windows %xNN% PAUSE
Compo, Yours is a set variable which is good for a read-out but the OP wanted a If/else with a goto so he/she could add further code.. Based on what Slave posted earlier the reg query may be the most reliable bit check method..DP Code: @echo off color 1f title, ~ O.S. BIT CHECKER ~ ::### Registry Query for bitness then goto either 32-bit or 64-bit.. REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "PROCESSOR_ARCHITECTURE" | FINDSTR AMD64 >nul IF '%ERRORLEVEL%' EQU '0' call :x64 REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "PROCESSOR_ARCHITECTURE" | FINDSTR x86 >nul IF '%ERRORLEVEL%' EQU '0' call :x86 :x86 echo 32-bit OS! :<code> pause>nul exit :x64 echo 64-bit OS! :<code> pause>nul exit
They certainly don't need an if/else, but here it is spoon fed… Code: @ECHO OFF SETLOCAL SET xNN=x%PROCESSOR_ARCHITECTURE:~-2% IF %xNN% EQU x86 (IF DEFINED PROCESSOR_ARCHITEW6432 SET xNN=x64) CALL :%xNN% PAUSE GOTO :EOF :x86 ECHO( Windows %xNN% GOTO :EOF :x64 ECHO( Windows %xNN% The PAUSE is only for effect and not a requirement. @Dos_Probie your idea needs improvement anyhow because you are running the same reg.exe query twice. Code: @ECHO OFF REG QUERY "HKLM\SYSTEM\CURRENTCONTROLSET\CONTROL\SESSION MANAGER\ENVIRONMENT" /V PROCESSOR_ARCHITECTURE|FIND "64">NUL && (GOTO :x64) ECHO( Windows x86 PAUSE GOTO :EOF :x64 ECHO( Windows x64 PAUSE
@Compo, Thanks for the info, your revised code of mine pops up a error with "unable to find the specified registry key blah blah.." but can be corrected with a cheater clear screen command, and yes my req query code was redundant so I revised it to a one-liner and also added a processor bit check just for good measure.. DP Code: @echo off :: Ck OS bit IF /I "%PROCESSOR_ARCHITECTURE%"=="x86" (IF NOT DEFINED PROCESSOR_ARCHITEW6432 GOTO :x86) :x64 echo System OS Architecture is 64-bit :<code> goto :proc :x86 echo System OS Architecture is 32-bit :<code> :proc :: Ck Proc bit set arch=HKLMHardwareDescriptionSystemCentralProcessor reg query %arch% 2>nul | find /I /N "x86">nul If [%ERRORLEVEL%] == [0] ( echo Running on a 32-bit processor.. pause>nul ) else ( echo Running on a 64-bit Processor.. ) echo. pause>nul exit
There was strangely a missing space between SESSION and MANAGER, now fixed. Incidentally, there is no benefit in trying to modify my code in an attempt to improve it, especially if you are not doing so. Here is your attempt fixed: Code: @ECHO OFF REM Check OS bit IF "%PROCESSOR_ARCHITECTURE:~-2%"=="86" (IF DEFINED PROCESSOR_ARCHITEW6432 GOTO x64) ECHO( System OS Architecture is 32-bit GOTO proc :x64 ECHO( System OS Architecture is 64-bit :proc REM Check Processor bit REG QUERY HKLM\HARDWARE\DESCRIPTION\SYSTEM\CENTRALPROCESSOR\0 /V IDENTIFIER|FIND "x86">NUL && ( ECHO= Running on a 32-bit processor..)||(ECHO= Running on a 64-bit Processor..) ECHO( PAUSE>NUL
dos-probie code from post #26 works.... compo code from post #27 does NOT ! ..... reports wrong OS arch
Hmm...this is what i normally use: Code: for /f "tokens=2* delims= " %%a in ('reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v "PROCESSOR_ARCHITECTURE"') do ( if "%%b" == "AMD64" goto :JumpTarget01 if "%%b" == "x86" goto :JumpTarget02 )
I still recon it's quickest to use %processor_architecture%. It's on every MS OS since XP. No need to look at reg at all... Code: if %processor_architecture% == AMD64 goto 64bit if %processor_architecture% == x86 goto 32bit
OK...would say, most working solutions are found . Obviously there are a lot of roads leading to success. Objectively seen i would say Flipp3r wins with short lead when it comes to keep it as short as possible . Otherwise Mr Jinje gave first correct answer . [...still love the 'for' loop, as they look that sophisticated ]
Flip, I think yours takes the prize!, clean and to the point, here is another take based on your code..(tested and working) DP Code: @setlocal enableextensions enabledelayedexpansion @echo off if !processor_architecture! == AMD64 (goto 64bit) else (goto 32bit) :64bit echo Running 64-bit endlocal pause :32bit echo Running 32-bit endlocal pause
Yep, options are good, been working on a Office 2010 and 2013 check activation script for both x64-x86 OS as well as x64-x86 Office, so this post came at a good time for me anyway based from Flipp's code , I discovered all you really need is just one line and it works brilliantly! Time for me to go to bed now..nite all DP Code: @echo off if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto 64BIT :32BIT echo 32-bit OS pause :goto End :64BIT echo 64-bit OS pause :End exit
For your Office Check...using myself this way to determine existence and install path of Office . Code: :: Rearm Office :RearmOffice reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot" >nul 2>&1 if errorlevel 1 goto :RearmOffice1432 FOR /F "tokens=2*" %%a IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot" /v "Path"') do (SET officepath=%%b) >nul 2>&1 cls echo: echo ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ echo Office 2010 Professional Plus %OSx% found echo in path: %officepath% echo: echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß echo: echo: CHOICE /C RS /M " [R]earm or kip ? : " if %errorlevel%==1 goto :RO1 if %errorlevel%==2 goto :RearmOffice1432 :RO1 echo: "%officepath%\ospprearm.exe" echo: timeout /t 5 :RearmOffice1432 reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot" >nul 2>&1 if errorlevel 1 goto :RearmOffice15 FOR /F "tokens=2*" %%a IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot" /v "Path"') do (SET officepath=%%b) >nul 2>&1 cls echo: echo ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ echo Office 2010 Professional Plus x86 found echo in path: %officepath% echo: echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß echo: echo: CHOICE /C RS /M " [R]earm or kip ? : " if %errorlevel%==1 goto :RO2 if %errorlevel%==2 goto :RearmOffice15 :RO2 echo: "%officepath%\ospprearm.exe" echo: timeout /t 5 :RearmOffice15 reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot" >nul 2>&1 if errorlevel 1 goto :RearmOffice1532 FOR /F "tokens=2*" %%a IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot" /v "Path"') do (SET officepath=%%b) >nul 2>&1 cls echo: echo ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ echo Office 2013 Professional Plus %vera% found echo in path: %officepath% echo: echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß echo: echo: CHOICE /C RS /M " [R]earm or kip ? : " if %errorlevel%==1 goto :RO3 if %errorlevel%==2 goto :RearmOffice1532 :RO3 echo: "%officepath%\ospprearm.exe" echo: timeout /t 5 :RearmOffice1532 reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot" >nul 2>&1 if errorlevel 1 exit /b FOR /F "tokens=2*" %%a IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot" /v "Path"') do (SET officepath=%%b) >nul 2>&1 cls echo: echo ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ echo Office 2013 Professional Plus x86 found echo in path: %officepath% echo: echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß echo: echo: CHOICE /C RS /M " [R]earm or kip ? : " if %errorlevel%==1 goto :RO4 if %errorlevel%==2 exit /b :RO4 echo: "%officepath%\ospprearm.exe" echo: timeout /t 5 exit /b
Thanks for the batch Slave, Like the path location as well, would you happen to have the rearm batch as well? DP
Slave, Is your code only for Win7 or will it work for Win 8.1? get a error with doing the rearm, don't need a rearm for windows but for Office is all. thanks dp
Nope works for Win 8/8.1 likewise. Rearm was only for a test batch to rearm a glitched Office install on one of my test VMs with Win 8.1 and Office 15. What error do you recieve?
I am running Office 2013 x64 on Win8.1 and I get this message. "There was an error trying to rearm Office...blah blah Error: 0xc004f025" Thanks for the help, DP