Reputation: 5264
On my 32 bit system (Windows 10), I created a very simple Windows Forms (.NET FW 3.5) application:
bool x86 = IntPtr.Size == 4;
if (x86)
{
label1.Text = "OS: 32 bit";
}
else // IntPtr.Size == 8
{
label1.Text = "OS: 64 bit";
// For following method, see:
// http://stackoverflow.com/a/336729/360840
if (InternalCheckIsWow64())
{
label1.Text += "; 32 bit program running under WoW64";
}
}
In Visual Studio 2015, under Properties -> Build, I set Platform Target as x86.
I took this executable to a 64 bit Windows Server 2012 Datacenter edition, and ran it. I fully expected to see it report itself as running under WoW64, but was surprised to find out that wasn't the case; it only reports that the architecture is 64 bit, but does not display the "; 32 bit program running under WoW64" part.
Why is this, and what is going on?
Upvotes: 2
Views: 750
Reputation: 681
IntPtr.Size is set by the process itself (or better said, the build target), not by the OS.
A program build with an x86 target in c# will always have IntPtr.Size = 4, while x64 will always have IntPtr.Size = 8. This is in fact a check for the process, not the OS.
Edit: The answer in the linked topic states exactly the same.
Upvotes: 1