Reputation: 7830
How to check if client computer is running a 32-bit or 64-bit OS in ASP.NET 3.5?
Upvotes: 2
Views: 7065
Reputation: 19
Checkout Environment.Is64BitOperatingSystem
It will return true if the operating system is 64-bit; otherwise, false.
Upvotes: 1
Reputation: 882
You can try displaying first the Server Variables for ASP.NET, like this:
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:
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)
As per this link, it means:
(Windows-On-Windows 64-bit) A 32-bit application is running on a 64-bit processor
Upvotes: 0
Reputation: 2992
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.
Look at http://whatsmyuseragent.com/ to see what yours is, mine is showing WOW64:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like 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; 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?
Upvotes: 0
Reputation: 421988
There's no way to reliably determine whether a client runs a 64 bit operating system or a 32 bit one. 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.
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.
Upvotes: 4
Reputation: 1142
This should work:
System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
There are other native Win32 API which can determine the same:
http://msdn.microsoft.com/en-us/library/aa394373%28VS.85%29.aspx
Upvotes: 2