Open Command Window in Windows x64 mode

后端 未结 2 1623
太阳男子
太阳男子 2021-01-15 06:21

I have an application which is installed in x64. I want to execute this EXE in x64 command prompt.

CASE 1:

If I open the command prompt man

2条回答
  •  长情又很酷
    2021-01-15 07:16

    It looks like you are using a 32-bit executable to run the batch file with elevated privileges. In this case the batch file is executed with 32-bit cmd.exe in %SystemRoot%\SysWOW64, see the Microsoft articles:

    • File System Redirector
    • WOW64 Implementation Details
    • Registry Keys Affected by WOW64

    As the batch file is already executed with elevated privileges and just needs to be processed by 64-bit cmd.exe on 64-bit Windows, here are the few lines to make sure that the batch file is executed by 64-bit Windows command processor on 64-bit Windows.

    @echo off
    if "%ProgramFiles(x86)%" == "" goto MainCode
    if not exist %SystemRoot%\Sysnative\cmd.exe goto MainCode
    %SystemRoot%\Sysnative\cmd.exe /C "%~f0" %*
    goto :EOF
    
    :MainCode
    set Program
    pause
    

    Put your main batch code below the label :Maincode.

    The first IF condition jumps to main batch code if the batch file is running on 32-bit Windows where the environment variable ProgramFiles(x86) does not exist at all.

    The second IF condition only executed on 64-bit Windows jumps to main batch code if it cannot find the file %SystemRoot%\Sysnative\cmd.exe because the batch file is processed already by 64-bit cmd.exe.

    Sysnative is not a directory. It is a special alias which exists only when 32-bit environment is active on 64-bit Windows. For that reason it is only possible to use, for example, the condition if exist %SystemRoot%\Sysnative\* to check for existence of any file, but not the condition if exist %SystemRoot%\Sysnative to check for existence of the directory because of Sysnative is not a directory.

    For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.

    • cmd /?
    • echo /?
    • goto /?
    • if /?
    • pause /?
    • set /?

提交回复
热议问题