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

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

  1. N7epsilon

    N7epsilon MDL Novice

    Dec 7, 2013
    7
    0
    0
    #1 N7epsilon, Jan 17, 2014
    Last edited by a moderator: Apr 20, 2017
    Hi.
    I'm looking for a cmd file detect if the system kernel x64 or x32 , becuse itry with this batch and it did't work , my plan is to add windows 7 driver cd's in AIO win 7 dvd vi setupcomplete.cmd but the problem is the too diffrent sourse of os , here is the setupcomplete.cmd sample what i use to run the drivers instaler :

    Code:
    echo off
    
    echo Detecting OS processor type :-------------------------------- if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto 64BIT echo 32-bit OS %~dp0"wandrv32.exe" goto END :64BIT echo 64-bit OS %~dp0"wandrv(64).exe" ​
     
  2. Mr Jinje

    Mr Jinje MDL Expert

    Aug 19, 2009
    1,770
    1,101
    60
    #2 Mr Jinje, Jan 17, 2014
    Last edited by a moderator: Apr 20, 2017
    Maybe this work better ?
    Code:
    start /b /wait powershell.exe -command "$ARCH = (Get-WmiObject -class Win32_OperatingSystem | Select-Object OSArchitecture).OSArchitecture;If ($ARCH -eq '64-bit') {Write-Host $ARCH;.\wandrv64.exe}else{Write-Host $ARCH;.\wandrv32.exe}"
    #
    
     
  3. N7epsilon

    N7epsilon MDL Novice

    Dec 7, 2013
    7
    0
    0
    #3 N7epsilon, Jan 17, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    thanx alot :biggrin: i'll test it .
     
  4. N7epsilon

    N7epsilon MDL Novice

    Dec 7, 2013
    7
    0
    0
    it dos't work curntlly
     
  5. N7epsilon

    N7epsilon MDL Novice

    Dec 7, 2013
    7
    0
    0
    I have successfully run the process by Batch and not a cmd file , thanks again
     
  6. MrMagic

    MrMagic MDL Guru

    Feb 13, 2012
    6,015
    4,148
    210
    Or Control Panel\All Control Panel Items\System
     
  7. N7epsilon

    N7epsilon MDL Novice

    Dec 7, 2013
    7
    0
    0
    It seems you did not understand what I mean. I asked it to integrate the cmd whit an un attended windows 7 dvd
     
  8. Mr Jinje

    Mr Jinje MDL Expert

    Aug 19, 2009
    1,770
    1,101
    60
    #8 Mr Jinje, Jan 17, 2014
    Last edited by a moderator: Apr 20, 2017
    This works fine on my x64, (at least for echoing the correct bit-ness), problem must be your file-names. Why parentheses in the (64) in the file, but no parentheses in the 32 bit ?

    Code:
    @ECHO OFF
    
    echo Detecting OS processor type
    :--------------------------------
    
    if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto 64BIT
    echo 32-bit OS
    %~dp0wandrv32.exe
    goto END
    :64BIT
    echo 64-bit OS
    %~dp0wandrv(64).exe
    PAUSE
     
  9. MrMagic

    MrMagic MDL Guru

    Feb 13, 2012
    6,015
    4,148
    210
    It seems you are right
     
  10. alanfox

    alanfox MDL Novice

    Jan 19, 2014
    2
    1
    0
    I struggled with this for some time then realized that if "C:\Program Files (86)" is present (cmd file IF EXISTS ....) then this is x64 Windows.
     
  11. N7epsilon

    N7epsilon MDL Novice

    Dec 7, 2013
    7
    0
    0
    Hi evryone agin ' itry all this on VHD and itd't work corctly seems to something rong whith it can any body add anew way to test it > :(
     
  12. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    895
    482
    30
    #12 KNARZ, Jan 22, 2014
    Last edited by a moderator: Apr 20, 2017
    To avoid any irritations i'm using my own variables.
    within my helper.cmd I definied programfiles like this...

    Code:
    
    ::Programfiles
    if [%PROCESSOR_ARCHITECTURE%] == [AMD64] (
        set "pf86=%programfiles(x86)%"
        set "pf64=%programfiles%"
    
    ) else (
        set "pf86=%programfiles%"
    )
    
    with this easy few lines I'm always sure that I'm pointing to the right directory.
    maybe this is something for you.
     
  13. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,964
    907
    60
    #13 Flipp3r, Jan 22, 2014
    Last edited by a moderator: Apr 20, 2017
    This is what I use to install my OS:
    Code:
    if %processor_architecture% == AMD64 \Source.x64\setup /unattend:%PTH%Files\Unattend-BIOS.xml
    if %processor_architecture% == x86 \Source.x86\setup /unattend:%PTH%Files\Unattend-BIOS.xml
    If you have both 32 & 64 bit executable's, you can rename them & call them from your batch:
    Files: Recoverx86.exe & RecoverAMD64.exe
    Code:
    @echo off
    Recover%processor_architecture%
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. Kamrul08

    Kamrul08 MDL Member

    Dec 28, 2013
    104
    13
    10
    @echo off
    mode con lines=10 cols=40
    IF EXIST "%ProgramFiles(x86)%" goto 64bit
    IF EXIST "%ProgramFiles%" goto 32bit


    :64bit
    ECHO.
    ECHO.
    echo. Your Operating System is 64bit.
    ping localhost -n 4 >nul
    exit /b


    :32bit
    ECHO.
    ECHO.
    echo. Your Operating System is 32bit.
    ping localhost -n 4 >nul
    exit /b
     
  15. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    #15 Dos_Probie, Feb 18, 2014
    Last edited by a moderator: Apr 20, 2017
    3-Way OS Check

    Most of the listed methods will work but I prefer to check for a file rather than Programs x86 , I ran across a system last year where someone made a X86 directory with a 32-bit system so it would error out, also the AMD method is good for AMD systems but there are also Intelx64 systems as well, and last the ping is a old carry over from XP so I perfer to use the timeout command..Here is a 3-way check that should give you your basic info you can use all or cherry pick out what you want..DP
    Code:
    @echo off&color 1f&mode con:cols=68 lines=8
    :: 3-Way Check for Bitness, OS Version and Full or Upgrade
    :: 02.18.14 ~DosProbie
    
    :: ### Ck Windows OS Version..
    for /f "usebackq tokens=1,* delims==" %%a in (`wmic os get caption /format:list ^| findstr "^Caption="`) do (
        set %%a=%%b
    )
    title, %Caption%
    
    :: ### Ck If Windows OS Is Full or Upgrade Version..
    set regpath=hklm\software\microsoft\windows\currentversion\setup\oobe
    set regvalue=MediaBootInstall
    set regdata=1
    
    reg query "%regpath%" /v "%regvalue%" | findstr /r "%regdata%">nul 2>&1
    cls
    :: ### OUTPUT IF FULL OR UPGRADE..
    if "%errorlevel%" equ "1" (
    
     title, %Caption%is a Full Version!
    ) else (
     title, %Caption%is a Upgrade Version!
    )
    
    :: ### Ck OS Bitness..
    if exist "%systemroot%\syswow64\cmd.exe" (call :x64) else (call :x86)
    
    :x86
    echo %Caption%32-bit OS.. && timeout /t 5 >nul
    ::< code > 
    exit
    
    :x64
    echo %Caption%64-bit OS.. && timeout /t 5 >nul
    ::< code > 
    exit
    
     
  16. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #16 s1ave77, Feb 18, 2014
    Last edited by a moderator: Apr 20, 2017
    There ain't no 'AMD'-Method, even an Intel system will give out 'AMD64'. Running an Intel i5 here :cool2:.

    Code:
    C:\Windows\System32>reg query "HKLM\System\CurrentControlSet\Control\Session Man
    ager\Environment" /v "PROCESSOR_ARCHITECTURE"
    
    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment
        PROCESSOR_ARCHITECTURE    REG_SZ    AMD64
    
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    #17 Dos_Probie, Feb 18, 2014
    Last edited by a moderator: Apr 20, 2017
    My req query reads as follows:
    Code:
    PROCESSOR_ARCHITECTURE = x86
    PROCESSOR_IDENTIFIER = x86 Family 6 Model 42 Stepping 7, GenuineIntel
     
  18. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #18 s1ave77, Feb 18, 2014
    Last edited by a moderator: Apr 20, 2017
    On a x64 System...? I was talking about the AMD64 string on x64 Systems.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,964
    907
    60
    Yes, s1ave77 is totally correct. If processor_architecture = AMD64 then your running a 64bit OS. It has nothing to do with Intel or AMD!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. user_hidden

    user_hidden MDL Expert

    Dec 18, 2007
    1,034
    1,061
    60

    nope not worthy !
    very basic and unreliable way of detecting OS arch