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

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

  1. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,130
    24,251
    340
    OK...although the queries will work, Rearm won't work for Office 14 :hmm:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Compo

    Compo MDL Member

    Mar 29, 2011
    137
    108
    10
    @Dos_Probie, since you believe my code from #24 errors out, because of the use of x64 and not AMD64. I'd be interested to see you step through my code line by line and explain exactly where you believe that to be the case.

    @user_hidden, could you please explain which of my code, since #27 isn't mine, reports the wrong operating system architecture, and provide more details.

    Collectively you seem happy to use incorrect solutions, do you want me to explain why the code posted, which is directly related to the topic title, in the following posts is incorrect; #28, #29, #30, #32 ,#35.
     
  3. Compo

    Compo MDL Member

    Mar 29, 2011
    137
    108
    10
    Not good enough, if you think my code is wrong please explain why.
    I only used x64 twice in that code, once as a label and once as a goto for that label, I haven't used it in any query, please try again.
     
  4. Compo

    Compo MDL Member

    Mar 29, 2011
    137
    108
    10
    #44 Compo, Feb 20, 2014
    Last edited by a moderator: Apr 20, 2017
    @Dos Probie

    Try the following in a console window
    Code:
    ECHO(AMD64|FINDSTR AMD64
    Then try this in the same window
    Code:
    ECHO(AMD64|FIND "64"
    Then try once again to explain what you are telling me is wrong.

    [EDIT /]
    Instead of apologizing for mistakenly stating that my code was wrong, you could just ignore it and hope nobody notices.

    Incidentally you are correct in saying that the code you posted is short and not over engineered, however as with the code in the five other posts I mentioned, it is also wrong!
     
  5. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    84
    10
    #45 Dos_Probie, Feb 22, 2014
    Last edited by a moderator: Apr 20, 2017
    Here is a OS bitness to variable based from some of the posts here plus a system-computer info batch to go along with it..
    Code:
    @echo off
    :: Get OS Bitness With Variable
    Echo %PROCESSOR_ARCHITECTURE%|Findstr 64>Nul && SET arch=(64-bit)||SET arch=(32-bit)
    Echo arch
    pause>nul
    exit
    
    PS @ Compo - I stand Corrected! after further review of your code from post #24 I discoverd that orginally you had incorrect spacing with "SessionManager" and not as "Session Manager" but you since have corrected it (as you mentioned in #25), additionally when using Find or Findstr it makes no difference when using 64 or AMD64 as it searches for the number and does not require AMD64 to respond correctly. Sorry for the confusion.
    DP :rolleyes:
    Code:
    @echo off&&setlocal
    
    :: = BASIC COMPUTER/SYSTEM INFORMATION =
    
    :: Cleanup old file if exist
    if exist %userprofile%\desktop\%username%.txt del %userprofile%\desktop\%username%.txt
    
    :: Runas Administrator
    REM  --> Check for permissions
    >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
    REM --> If error flag set, we do not have admin.
    if '%errorlevel%' NEQ '0' (
        echo Requesting administrative privileges...
        goto UACPrompt
    ) else ( goto gotAdmin )
    :UACPrompt
        echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
        echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
        "%temp%\getadmin.vbs"
        exit /B
    :gotAdmin
        if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
        pushd "%CD%"
        CD /D "%~dp0"
    
    :: Title Block
    set daydate=%date% 
    for /f "tokens=1,2" %%a in ('time/t') do set time12=%%a %%b
    title, Basic Computer Info by: ~DosProbie  %daydate% @ %time12%
    color 1f&mode con:cols=72 lines=20 
     
    echo Press any [KEY] To Get Your Computer Information ...&pause>nul&goto :ci
    :ci
    cls
    :: Processor Info
    for /f "tokens=2 delims==" %%I in (
      'wmic cpu where "manufacturer!=\"Microsoft\" and name is not null" get name /format:list 2^>NUL'
    ) do SET proc=%%I >>%userprofile%\desktop\%username%.txt
    ::FOR /F "tokens=2 delims='='" %%A in ('wmic cpu get caption /value') do SET caption=%%A 
    :: Get Computer OS
    FOR /F "tokens=2 delims='='" %%A in ('wmic os get Name /value') do SET osname=%%A 
    FOR /F "tokens=1 delims='|'" %%A in ("%osname%") do SET osname=%%A 
    :: Get OS Bitness
    Echo %PROCESSOR_ARCHITECTURE%|Findstr AMD64>Nul && SET arch=(64-bit)||SET arch=(32-bit) 
    :: Internet Explorer Version
    (For /f "Tokens=1,2*" %%a In ('reg query "HKLM\Software\Microsoft\Internet Explorer" /v svcVersion') Do Set IE_Ver=%%c) 2>nul
    :: Get Mac Address
    for /f "tokens=2 delims==" %%I in (
        'wmic nic where "manufacturer!=\"Microsoft\" and macaddress is not null" get macaddress /format:list 2^>NUL' 
    ) do SET macaddy=%%I 
    :: ISP Domain
    for /f "tokens=2 delims=:" %%# In ('IPConfig /all^|Find "DNS Suffix Search List"') Do (
    for %%$ In (%%#) Do Set ISPDomain=%%$)
    :: Network Profile Name
    for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa&goto :gotit
    :gotit
    for /f "tokens=2,*" %%b in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\%var%" ^| FIND "ProfileName"') do SET NetProfile=%%%c
    :: IP Address
    for /f "tokens=2 delims=:" %%# In ('IPConfig^|Find "IPv4"') Do ( 
    Call :Addy %%#) 
    :Addy 
    Set IP=%1 
    :: Get Computer Serial Number
    FOR /F "tokens=2 delims='='" %%A in ('wmic Bios Get SerialNumber /value') do SET serialnumber=%%A 
    :: Get Computer Manufacturer
    FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Manufacturer /value') do SET manufacturer=%%A 
    :: Get Computer Model
    FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Model /value') do SET model=%%A 
    :: Get Computer Name
    FOR /F "tokens=2 delims='='" %%A in ('wmic OS Get csname /value') do SET system=%%A 
    :: Total Physical Installed (RAM)
    for /f "Tokens=4*" %%G In ('SystemInfo 2^>nul^|find ^"Total Physical Memory^"') Do Set "memory=%%G"
    :: Get Service Pack
    FOR /F "tokens=2 delims='='" %%A in ('wmic os get ServicePackMajorVersion /value') do SET sp=%%A 
    echo =============== COMPUTER INFORMATION =============== >>%userprofile%\desktop\%username%.txt
    echo ---------------------------------------------------- >>%userprofile%\desktop\%username%.txt
    echo Info For: %username% >>%userprofile%\desktop\%username%.txt
    echo Proc Info: %proc% >>%userprofile%\desktop\%username%.txt
    echo O.S.: %osname% %arch% >>%userprofile%\desktop\%username%.txt
    echo IE Version: %IE_Ver% >>%userprofile%\desktop\%username%.txt
    echo Mac Address: %macaddy% >>%userprofile%\desktop\%username%.txt
    echo ISP Domain: %ISPDomain% >>%userprofile%\desktop\%username%.txt
    echo Profile Name: %netprofile% >>%userprofile%\desktop\%username%.txt
    echo IP Address: %IP% >>%userprofile%\desktop\%username%.txt
    echo Serial Number: %serialnumber% >>%userprofile%\desktop\%username%.txt
    echo Manufacturer: %manufacturer% >>%userprofile%\desktop\%username%.txt
    echo Model: %model% >>%userprofile%\desktop\%username%.txt
    echo System Name: %system% >>%userprofile%\desktop\%username%.txt
    echo Usable Memory: %memory% >>%userprofile%\desktop\%username%.txt
    echo Service Pack: %sp% >>%userprofile%\desktop\%username%.txt
    echo ---------------------------------------------------- >>%userprofile%\desktop\%username%.txt
    echo ============ %daydate% @ %time12% ============ >>%userprofile%\desktop\%username%.txt
    :: Printout to desktop
    type %userprofile%\desktop\%username%.txt
    echo.
    echo Saved to: %userprofile%\desktop\%username%.txt...Keep y/n ?
    set /p ch=
    if %ch%==y exit
    if %ch%==n del %userprofile%\desktop\%username%.txt
    if %ch%==Y exit
    if %ch%==N del %userprofile%\desktop\%username%.txt
    :end
    endlocal
    exit
    :: ~DosProbie - Tested on: Windows 7/8 - 02.22.14
    
     
  6. Compo

    Compo MDL Member

    Mar 29, 2011
    137
    108
    10
    #46 Compo, Feb 22, 2014
    Last edited by a moderator: Apr 20, 2017
    regardless of the fact that the code you've posted can be improved it once again has the same inherent problem. I'm sure that it will work in the majority of cases but what about covering all options?

    Try taking a proper look at 'my solution', (posted again below), and see if by questioning the code you can form an opinion on why I did what I did!

    When I first posted code on here, I was told that the members wanted to be able to learn from it. Someone who has a basic understanding of batch scripting such as yourself should step through the code and ask yourself, why did they do that. Even if you cannot work out why, at least ask the questions instead of trying to better it and failing.

    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%
     
  7. N7epsilon

    N7epsilon MDL Novice

    Dec 7, 2013
    7
    0
    0
    #47 N7epsilon, Apr 12, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    hi every one i try this method and it work with me so fine , ido alot of thanks for every one who share his work with me ,

    Code:
    @echo off
    Color 07
    SET "S_Version=v0.0.1"
    SET "S_Title= Easy Driver Pack Finder For AIO windows 7 "
    
    ::### 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
    if EXIST %systemdrive%\D\D86\wandr.exe goto Yes
    START %systemdrive%\D\D86\wandrv.exe
    echo
    :<code>
    exit
    
    :x64
    if EXIST %systemdrive%\D\D64\wandr.exe goto Yes
    START %systemdrive%\D\D64\wandrv.exe
    :<code>
    exit
    
    
    
     
  8. Compo

    Compo MDL Member

    Mar 29, 2011
    137
    108
    10
    #48 Compo, May 10, 2014
    Last edited by a moderator: Apr 20, 2017
    This would be more efficient
    Code:
    @Echo off & SetLocal
    Color 07
    Set "S_Version=v0.0.1"
    Set "S_Title= Easy Driver Pack Finder For AIO windows 7 "
    
    Rem ### Query for bitness..
    Set Dnn=D%PROCESSOR_ARCHITECTURE:~-2%
    If %Dnn% Equ D86 (If Defined PROCESSOR_ARCHITEW6432 Set Dnn=D64)
    
    If Exist %SYSTEMDRIVE%\D\%Dnn%\wandr.exe GoTo :Yes
    Start %SYSTEMDRIVE%\D\%Dnn%\wandrv.exe
    Echo(
    :<code>
    Exit
     
  9. xinso

    xinso MDL Guru

    Mar 5, 2009
    5,104
    7,191
    180
    #49 xinso, May 17, 2014
    Last edited by a moderator: Apr 20, 2017
    Compo,

    For KMS-QADhooker to work, it needs

    1. two files located in C:\Windows

    2. a registry entry of KMS-QADhooker.exe
    Code:
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\SppExtComObj.exe]
    "Debugger"="KMS-QADhooker.exe"
    I am using script below to detect if three things were in place. If all existed, skip. If not, copy files and import registry.
    Code:
    :FndQAD
    if not exist %SystemRoot%\KMS-QADhooker.exe (call:AddQAD&goto:eof)
    if not exist %SystemRoot%\KMS-QADhooker.dll (call:AddQAD&goto:eof)
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\SppExtComObj.exe" /v Debugger 2>nul | findstr /i KMS-QADhooker.exe >nul 2>&1
    if %errorlevel% neq 0 (call:AddQAD&goto:eof) else (goto:eof)
    Now I need your help to see if it could be improved to be more efficient or neat and clean.

    Something like

    if A | if B | if C && goto:eof || call:AddQAD&goto:eof

    Thanks.

    EDIT: Compo, I found this works

    if A if B if C && goto:eof
    call:AddQAD&goto:eof

    Code:
    :FndQAD
    if exist %SystemRoot%\%QAD%.exe if exist %SystemRoot%\%QAD%.dll reg query "%NTCV%\Image File Execution Options\SppExtComObj.exe" /v Debugger 2>nul | findstr /i %QAD%.exe >nul&&%INEL1% (goto:eof)
    
    call:AddQAD&goto:eof
    
    EDIT: One more question, please:

    For Office 2013 slipstream, though it won't promt message while running in the background. But I'd like to keep it from prompting message "File not found" when I tested it in the foreground. Thanks.

    Code:
    :O15Setup
    for /f %%i in ('dir /b/a:d "%DRIVE%\support\Office\%ARCH%"') do if exist %DRIVE%\support\Office\%ARCH%\%%i\%%i.ww\config.xml (%DRIVE%\support\Office\%ARCH%\%%i\setup.exe /config %%i.ww\config.xml)
    
    for /f %%i in ('dir /b/a:d "%DRIVE%\support\office\%ARCH%\*.ww"') do if exist %DRIVE%\support\Office\%ARCH%\%%i\config.xml (%DRIVE%\support\Office\%ARCH%\setup.exe /config %%i\config.xml)
    goto:eof
     
  10. Compo

    Compo MDL Member

    Mar 29, 2011
    137
    108
    10
    #50 Compo, May 18, 2014
    Last edited by a moderator: Apr 20, 2017
    The addition should prevent the message from showing
     
  11. xinso

    xinso MDL Guru

    Mar 5, 2009
    5,104
    7,191
    180
    It is working fine. Thanks a lot, Compo.
     
  12. tyhaitrieu6

    tyhaitrieu6 MDL Novice

    Jun 16, 2014
    6
    0
    0
    It's good to have options & samples. The reg/for stuff could be handy for other tasks... ​