Ash*_*hok 104 windows environment-variables windows-7-x64
我想知道如何在命令提示符下显示Program Files(x86)的位置.我正在使用Windows 7 64位.
我试过了:
echo %programfiles(x86)%并且echo %programfiles%,
两者都只显示C:\Program Files
当我手工检查注册表,
HKLM /软件/微软/窗/ CURRENTVERSION,
该programfilesdir点C:\Program Files与
HKLM /软件/ WOW64 /微软/的Winodws/CURRENTVERSION,
该programfilesdir点C:\Program Files (x86).
但是,为什么我总是用C:\ Program Files?
Sec*_*att 169
在以64位模式运行的64位计算机上:
echo %programfiles% ==> C:\Program Filesecho %programfiles(x86)% ==> C:\Program Files (x86)在以32位(WOW64)模式运行的64位计算机上:
echo %programfiles% ==> C:\Program Files (x86)echo %programfiles(x86)% ==> C:\Program Files (x86)在以32位模式运行的32位计算机上:
echo %programfiles% ==> C:\Program Filesecho %programfiles(x86)% ==> %programfiles(x86)%Vin*_*ini 32
另一个相关的环境变量是:
因此,在以32位(WOW64)模式运行的64位计算机上:
- echo%programfiles%==> C:\ Program Files(x86)
- echo%programfiles(x86)%==> C:\ Program Files(x86)
- echo%ProgramW6432%==> C:\ Program Files
来自维基百科:
%ProgramFiles%变量指向Program Files目录,该目录存储Windows和其他所有已安装的程序.英语系统的默认设置是"C:\ Program Files".在64位版本的Windows(XP,2003,Vista)中,还有%ProgramFiles(x86)%,默认为"C:\ Program Files(x86)"和%ProgramW6432%,默认为"C:\Program Files".%ProgramFiles%本身取决于请求环境变量的进程本身是32位还是64位(这是由Windows-on-Windows 64位重定向引起的).
参考:http://en.wikipedia.org/wiki/Environment_variable
在 64 位 Windows 系统上,各种环境变量和某些 Windows 注册表项的读取会重定向到不同的源,具体取决于执行读取的进程是 32 位还是 64 位。
下表列出了这些数据源:
X = HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion
Y = HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion
Z = HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
READING ENVIRONMENT VARIABLES: Source for 64-bit process Source for 32-bit process
-------------------------------|----------------------------------------|--------------------------------------------------------------
%ProgramFiles% : X\ProgramW6432Dir X\ProgramFilesDir (x86)
%ProgramFiles(x86)% : X\ProgramFilesDir (x86) X\ProgramFilesDir (x86)
%ProgramW6432% : X\ProgramW6432Dir X\ProgramW6432Dir
%CommonProgramFiles% : X\CommonW6432Dir X\CommonFilesDir (x86)
%CommonProgramFiles(x86)% : X\CommonFilesDir (x86) X\CommonFilesDir (x86)
%CommonProgramW6432% : X\CommonW6432Dir X\CommonW6432Dir
%ProgramData% : Z\ProgramData Z\ProgramData
READING REGISTRY VALUES: Source for 64-bit process Source for 32-bit process
-------------------------------|----------------------------------------|--------------------------------------------------------------
X\ProgramFilesDir : X\ProgramFilesDir Y\ProgramFilesDir
X\ProgramFilesDir (x86) : X\ProgramFilesDir (x86) Y\ProgramFilesDir (x86)
X\ProgramFilesPath : X\ProgramFilesPath = %ProgramFiles% Y\ProgramFilesPath = %ProgramFiles(x86)%
X\ProgramW6432Dir : X\ProgramW6432Dir Y\ProgramW6432Dir
X\CommonFilesDir : X\CommonFilesDir Y\CommonFilesDir
X\CommonFilesDir (x86) : X\CommonFilesDir (x86) Y\CommonFilesDir (x86)
X\CommonW6432Dir : X\CommonW6432Dir Y\CommonW6432Dir
Run Code Online (Sandbox Code Playgroud)
例如,对于 32 位进程,环境变量的数据源%ProgramFiles%是%ProgramFiles(x86)%注册表值HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir (x86)。
但是,对于 64 位进程,环境变量的数据源%ProgramFiles%是注册表值HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramW6432Dir...而环境变量的数据源%ProgramFiles(x86)%是注册表值HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir (x86)
大多数默认的 Windows 安装都会将类似的字符串C:\Program Files (x86)放入注册表值中HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir (x86),但可以更改此值(以及其他值)。
在这些 Windows 注册表值中输入的任何内容都将在登录时由 Windows 资源管理器读取到相应的环境变量中,然后复制到随后生成的任何子进程。
注册表值HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesPath尤其值得注意,因为大多数 Windows 安装都会将字符串放入%ProgramFiles%其中,以供 64 位进程读取。该字符串引用环境变量%ProgramFiles%,该环境变量又从注册表值获取数据HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramW6432Dir...除非某些程序先验更改了该环境变量的值。
我编写了一个小实用程序,它显示 64 位和 32 位进程的这些环境变量。你可以在这里下载。
包含 VisualStudio 2017 的源代码,编译后的 64 位和 32 位二进制可执行文件分别位于目录..\x64\Release和中..\x86\Release。
| 归档时间: |
|
| 查看次数: |
226750 次 |
| 最近记录: |