【发布时间】:2010-10-10 16:59:22
【问题描述】:
信不信由你,我的安装程序太旧了,它没有检测 64 位版本 Windows 的选项。
是否有 Windows DLL 调用或(甚至更好)环境变量可以为 Windows XP 和 Windows Vista 提供该信息?
一种可能的解决方案
我看到 Wikipedia 指出 64 位版本的 Windows XP 和 Windows Vista 有一个独特的环境变量:%ProgramW6432%,所以我猜在 32 位 Windows 上它是空的。
这个变量指向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 位重定向引起的)。
【问题讨论】:
-
参考: - 如果您使用的是 .NET:How to detect Windows 64-bit platform with .NET? - 如果您想在 .NET 之外使用它:How to detect programmatically whether you are running on 64-bit Windows
-
我在这里发布了 MSDN / Perl 答案:stackoverflow.com/questions/2030039/…
-
为什么不使用新的安装程序? o_O
-
I see that Wikipedia states that the 64-bit version of Windows XP and Windows Vista have a unique environment variable: %ProgramW6432%, so I'm guessing that'd be empty on 32-bit Windows.不完全是。 Windows XP 似乎只保留了对它不知道的环境变量的引用。即echo %ProgramW6432%导致%ProgramW6432%被回显,而不是空字符串。但是,您应该仍然可以使用它,例如:if "%ProgramW6432%" == "Program Files" echo 64-bit OS detected或if not "%ProgramW6432%" == "Program Files" echo 32-bit OS detected
标签: windows batch-file 64-bit