在Windows x64模式下打开命令窗口 [英] Open Command Window in Windows x64 mode

查看:102
本文介绍了在Windows x64模式下打开命令窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个安装在x64中的应用程序.我想在x64命令提示符下执行此EXE.

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

案例1:

如果我以Admin(Start->Type, cmd.exe->Right click->Run as Administrator)手动打开命令提示符,则EXE可以正常工作.我在cmd窗口中使用SET命令获得了有关环境变量的以下规范:

If I open the command prompt manually as Admin (Start->Type, cmd.exe->Right click->Run as Administrator) then the EXE works fine. I get the following specifications about the Environment variables using SET command in cmd window:

CommonProgramFiles=c:\Program Files\Common Files
CommonProgramFiles(x86)=c:\Program Files (x86)\Common Files
CommonProgramW6432=c:\Program Files\Common Files
PROCESSOR_ARCHITECTURE=AMD64

案例2:

如果我使用提升为管理员权限的脚本文件打开命令"窗口,则找不到EXE.通过使用SET命令,我获得了环境变量的以下值:

If I open the Command window using a script file which elevates to the Admin rights then the EXE is not found. I get the following values for the environments variables by using SET command:

CommonProgramFiles=c:\Program Files (x86)\Common Files
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
ProgramFiles=c:\Program Files (x86)
ProgramFiles(x86)=c:\Program Files (x86)

winSysFolder=System32

问题:我必须处理 案例2 .我认为ProgramFiles路径中的差异可能是我的EXE在第二种情况下无法正常工作的原因. 如何在脚本中指定应在x64命令提示符下执行?

Question: I have to work with Case 2. I think that the discrepancy in the paths of ProgramFiles could be the reason of my EXE not working in the second case. How can I specify in the script that it should be executed in x64 command prompt?

PS:我主要问题的链接是这里.

PS: The link to my main problem is here.

参考文献:提升为Admin的脚本文件摘自Matt的回答在此处给出.

References: The script file to elevate to Admin has been taken from Matt's answer given here.

推荐答案

您似乎正在使用32位可执行文件以提升的特权运行批处理文件.在这种情况下,批处理文件是使用%SystemRoot%\SysWOW64中的32位cmd.exe执行的,请参阅Microsoft文章:

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

由于该批处理文件已经以提升的特权执行并且仅需要在64位Windows上由64位cmd.exe处理,因此以下几行内容可确保该批处理文件由64位执行64位Windows上的Windows命令处理器.

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

将您的主要批处理代码放在标签:Maincode下.

Put your main batch code below the label :Maincode.

如果批处理文件运行在完全不存在环境变量ProgramFiles(x86)的32位Windows上,则第一个 IF 条件将跳转到主批处理代码.

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.

仅在64位Windows上执行的第二个 IF 条件如果找不到该文件%SystemRoot%\Sysnative\cmd.exe,因为该批处理文件已经被64位cmd.exe处理,则跳转到主批处理代码.

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不是目录.这是一个特殊的别名,仅当在64位Windows上激活32位环境时才存在.因此,只能使用条件if exist %SystemRoot%\Sysnative\*来检查是否存在任何文件,而不能使用条件if exist %SystemRoot%\Sysnative来检查目录是否存在,因为Sysnative不是目录.

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 /?
  • cmd /?
  • echo /?
  • goto /?
  • if /?
  • pause /?
  • set /?

这篇关于在Windows x64模式下打开命令窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆