[Request] cmd batch to detect if the system x64 or x32

Discussion in 'Scripting' started by N7epsilon, Jan 17, 2014.

  1. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #21 Compo, Feb 18, 2014
    Last edited by a moderator: Apr 20, 2017
    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
     
  2. Dos_Probie

    Dos_Probie MDL Member

    Jul 18, 2012
    249
    86
    10
    That is what I said in my post above, will probably work but not the best way
    @Slave my bad..DP
     
  3. Dos_Probie

    Dos_Probie MDL Member

    Jul 18, 2012
    249
    86
    10
    #23 Dos_Probie, Feb 19, 2014
    Last edited by a moderator: Apr 20, 2017
    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:jockey:
    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
    
     
  4. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #24 Compo, Feb 19, 2014
    Last edited by a moderator: Apr 20, 2017
    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
     
  5. Dos_Probie

    Dos_Probie MDL Member

    Jul 18, 2012
    249
    86
    10
    #25 Dos_Probie, Feb 19, 2014
    Last edited by a moderator: Apr 20, 2017
    @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
     
  6. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #26 Compo, Feb 19, 2014
    Last edited by a moderator: Apr 20, 2017
    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
     
  7. user_hidden

    user_hidden MDL Expert

    Dec 18, 2007
    1,034
    1,062
    60
    dos-probie code from post #26 works....

    compo code from post #27 does NOT ! ..... reports wrong OS arch
     
  8. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,097
    24,396
    340
    #28 s1ave77, Feb 19, 2014
    Last edited by a moderator: Apr 20, 2017
    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
        )
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,990
    935
    60
    #29 Flipp3r, Feb 19, 2014
    Last edited by a moderator: Apr 20, 2017
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,097
    24,396
    340
    OK...would say, most working solutions are found :cool2:. 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 :D. Otherwise Mr Jinje gave first correct answer :good3:.

    [...still love the 'for' loop, as they look that sophisticated :smartass:]
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. Dos_Probie

    Dos_Probie MDL Member

    Jul 18, 2012
    249
    86
    10
    #31 Dos_Probie, Feb 20, 2014
    Last edited by a moderator: Apr 20, 2017
    Flip, I think yours takes the prize!, clean and to the point, here is another take based on your code..(tested and working)
    DP :jockey:
    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
     
  12. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,990
    935
    60
    It's good to have options & samples. The reg/for stuff could be handy for other tasks...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,097
    24,396
    340
    #33 s1ave77, Feb 20, 2014
    Last edited by a moderator: Apr 20, 2017
    In that case it would be useful to exit ... :D.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. Dos_Probie

    Dos_Probie MDL Member

    Jul 18, 2012
    249
    86
    10
    #34 Dos_Probie, Feb 20, 2014
    Last edited by a moderator: Apr 20, 2017
    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 :cool:
    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
     
  15. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,097
    24,396
    340
    #35 s1ave77, Feb 20, 2014
    Last edited by a moderator: Apr 20, 2017
    For your Office Check...using myself this way to determine existence and install path of Office :D.

    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
    
    
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. Dos_Probie

    Dos_Probie MDL Member

    Jul 18, 2012
    249
    86
    10
    Thanks for the batch Slave, Like the path location as well, would you happen to have the rearm batch as well?
    DP
     
  17. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,097
    24,396
    340
    Not sure, what you mean...:hmm:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. Dos_Probie

    Dos_Probie MDL Member

    Jul 18, 2012
    249
    86
    10
    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
     
  19. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,097
    24,396
    340
    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?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. Dos_Probie

    Dos_Probie MDL Member

    Jul 18, 2012
    249
    86
    10
    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