在 32 位 Windows 操作系统上使用 %PROGRAMFILES(x86)%

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17688758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:43:09  来源:igfitidea点击:

Using %PROGRAMFILES(x86)% on Windows OS 32bit

windowsenvironment-variables

提问by sazr

What happens when I use the environment variable %PROGRAMFILES(x86)%on a Windows OS that is 32bit (ie, older versions of Windows such as Windows XP, Vista)?

当我%PROGRAMFILES(x86)%在 32 位 Windows 操作系统(即旧版本的 Windows,如 Windows XP、Vista)上使用环境变量时会发生什么?

I am hoping that it will simply resolve to: C:/Program Files. Will this occur?

我希望它会简单地解决:C:/Program Files。这会发生吗?

回答by Roger Rowland

According to thisthe environment variable %PROGRAMFILES(x86)%is only available on 64-bit systems.

据此环境变量%PROGRAMFILES(x86)%仅在 64 位系统上可用。

However, if you are on a 64-bit system and use %PROGRAMFILES%, the result you get depend on whether the process requesting the environment variable is 32-bit or 64-bit.

但是,如果您使用的是 64 位系统并使用%PROGRAMFILES%,您得到的结果取决于请求环境变量的进程是 32 位还是 64 位。

So from a 64-bit process on a 64-bit system you would get C:\Program Files, from a 32-bit process on a 64-bit system you would get C:\Program Files (x86), and from a 32-bit process on a 32-bit system you would get C:\Program Files.

因此,从 64 位系统上的 64 位进程中,您将获得C:\Program Files,从 64 位系统上的 32 位进程中您将获得C:\Program Files (x86),从 32 位系统上的 32 位进程中您将获得C:\Program Files

If this doesn't help, perhaps you can comment or edit your original question to make it specific what you are trying to do. As it currently stands, the answer to your question is "No".

如果这没有帮助,也许您可​​以评论或编辑您的原始问题,以使其具体说明您要执行的操作。就目前而言,您的问题的答案是“否”。

回答by agabrys

Keith Hillanswered this question here, summary:

基思希尔在这里回答了这个问题,总结:

${env:ProgramFiles(x86)}is not defined on a 32-bit machine

${env:ProgramFiles(x86)}未在 32 位机器上定义

If you always want to put/get data to/from x86 directory, then you can use this code to determine file paths:

如果您总是想在 x86 目录中放置/获取数据,那么您可以使用此代码来确定文件路径:

$file = "\file"
if ("${Env:ProgramFiles(x86)}")
{
    $fullPath = "${Env:ProgramFiles(x86)}$file"
}
else
{
    $fullPath = "${Env:ProgramFiles}$file"
}

回答by uceumern

Since %ProgramFiles(x86)%is not defined on Windows 7 32 bit, here is a workaround I came up with:

由于%ProgramFiles(x86)%未在 Windows 7 32 位上定义,这是我想出的解决方法:

SET MyPath="%ProgramFiles(x86)%\MyFolder\MyApplication.exe"
rem workaround for Windows7 32 bit:
IF NOT DEFINED ProgramFiles(x86) SET MyPath="%PROGRAMFILES%\MyFolder\MyApplication.exe"

Use case: I want to call an application from a batch file that is installed:

用例:我想从安装的批处理文件中调用应用程序:

  • on Windows 7 32 bit in C:\Program Files\MyFolder\MyApplication.exe
  • on Windows 7 64 bit in C:\Program Files(x86)\MyFolder\MyApplication.exe
  • 在 C:\Program Files\MyFolder\MyApplication.exe 中的 Windows 7 32 位
  • 在 Windows 7 64 位上 C:\Program Files(x86)\MyFolder\MyApplication.exe

This way %MyPath%always points to the correct path.

这种方式%MyPath%总是指向正确的路径。

回答by Lee

If you use %programfiles%on a 32-bit computer/laptop it will open C:\Program Files.

如果您%programfiles%在 32 位计算机/笔记本电脑上使用,它将打开C:\Program Files.

If you use %programfiles%on a 64-bit computer/laptop it will open C:\Program Files.

如果您%programfiles%在 64 位计算机/笔记本电脑上使用,它将打开C:\Program Files.

If you have a 64-bit program installed on a 32-bit computer/laptop, it will be installed in a new folder named Program Files (x64), which is located in the "C" drive. In which case you have to use %programfiles(x64).

如果您在 32 位计算机/笔记本电脑上安装了 64 位程序,它将安装在名为 的新文件夹中Program Files (x64),该文件夹位于“C”驱动器中。在这种情况下,您必须使用%programfiles(x64).

If you have a 32-bit program installed on a 64-bit computer/laptop, it will be installed in a new folder named Program Files (x86), which is located in the "C" drive. In which case you have to use %programfiles(x86).

如果您在 64 位计算机/笔记本电脑上安装了 32 位程序,它将安装在名为 的新文件夹中Program Files (x86),该文件夹位于“C”驱动器中。在这种情况下,您必须使用%programfiles(x86).