简体   繁体   English

如何检查客户端计算机是否正在运行32位或64位OS

[英]How to check if client computer is running a 32-bit or 64-bit OS

如何检查客户端计算机是否在ASP.NET 3.5中运行32位或64位OS?

There's no way to reliably determine whether a client runs a 64 bit operating system or a 32 bit one. 无法可靠地确定客户端运行的是64位操作系统还是32位操作系统。 What if the client is not a full blown computer at all? 如果客户端根本不是功能强大的计算机怎么办?

All you can do without running any platform specific code on the client is to trust the user agent string passed by the browser. 您无需在客户端上运行任何特定于平台的代码就可以做的就是信任浏览器传递的用户代理字符串。 Some browsers, like Internet Explorer, do in fact send this clue in the user agent string. 实际上,某些浏览器(例如Internet Explorer)会在用户代理字符串中发送此线索。

For instance, 64-bit IE will send "Win64; x64" as part of the user agent string and 32-bit IE running on a 64-bit edition of Windows will send "WOW64" as part of it. 例如,64位IE将发送“ Win64; x64”作为用户代理字符串的一部分,而在64位版本的Windows上运行的32位IE将发送“ WOW64”作为其一部分。

This should work: 这应该工作:

System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")

There are other native Win32 API which can determine the same: 还有其他本机Win32 API可以确定相同的内容:

http://msdn.microsoft.com/en-us/library/aa394373%28VS.85%29.aspx http://msdn.microsoft.com/en-us/library/aa394373%28VS.85%29.aspx

Checkout Environment.Is64BitOperatingSystem 结帐Environment.Is64BitOperatingSystem

It will return true if the operating system is 64-bit; 如果操作系统是64位,它将返回true;否则,将返回true。 otherwise, false. 否则,错误。

You could look at the user agent to see what OS/Architecture the client is running on, but the user agent can be modified so isn't a 100% reliable source. 您可以查看用户代理以查看客户端正在运行的OS /体系结构,但是可以修改用户代理,因此不是100%可靠的来源。

Look at http://whatsmyuseragent.com/ to see what yours is, mine is showing WOW64: 查看http://whatsmyuseragent.com/ ,看看您的是什么,我正在显示WOW64:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.65 Safari/534.24 Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 534.24(KHTML,例如Gecko)Chrome / 11.0.696.65 Safari / 534.24

Other than that you may have to run some script on the client to determine what it is - looking for the environment "PROCESSOR_ARCHITECTURE" you're again relying on that variable being present; 除此之外,您可能还必须在客户端上运行一些脚本来确定脚本的内容-寻找环境“ PROCESSOR_ARCHITECTURE”,您再次依赖于存在的变量; in a potentially sandboxed environment, the broswer (or app) may not want you to see many environmental variables. 在潜在的沙盒环境中,浏览器(或应用程序)可能不希望您看到许多环境变量。

What's the reason for determining the OS 32/64bit architecture? 确定OS 32/64位体系结构的原因是什么?

You can try displaying first the Server Variables for ASP.NET, like this: 您可以尝试首先显示ASP.NET的服务器变量,如下所示:

       if (!IsPostBack) {
            int loop1, loop2;
            NameValueCollection coll;

            // Load ServerVariable collection into NameValueCollection object.
            coll = Request.ServerVariables;
            // Get names of all keys into a string array. 
            String[] arr1 = coll.AllKeys;
            for (loop1 = 0; loop1 < arr1.Length; loop1++) {
                Response.Write("Key: " + arr1[loop1] + "<br>");
                String[] arr2 = coll.GetValues(arr1[loop1]);
                for (loop2 = 0; loop2 < arr2.Length; loop2++) {
                    Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>");
                }
            }
        }

After that you can check the HTTP_USER_AGENT value: 之后,您可以检查HTTP_USER_AGENT值:

Key: HTTP_USER_AGENT Value 0: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64 ; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2; Zune 4.7; AskTbFXTV5/5.11.3.15590) 密钥:HTTP_USER_AGENT值0:Mozilla / 4.0(兼容; MSIE 8.0; Windows NT 6.1; WOW64 ; Trident / 4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2; Zune 4.7; AskTbFXTV5 / 5.11.3.15590)

As per this link , it means: 按照此链接 ,这意味着:

(Windows-On-Windows 64-bit) A 32-bit application is running on a 64-bit processor (Windows-On-Windows 64位)32位应用程序在64位处理器上运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM