WOW6432Node detection

V

VistaDB

OK, I know this has been discussed before. I need to detect when I am
running on 64 bit windows, and write a specific key to the 32 bit node
for VS 2005 to load my plugin (I am 64 bit, it is 32 bit).

ManagementObjectSearcher mso = new ManagementObjectSearcher("SELECT *
FROM Win32_OperatingSystem"); //Win32_ComputerSystem");
ManagementObjectCollection qc = mso.Get();

Console.WriteLine("OSArchitecture: " +
mo["OSArchitecture"].ToString());

That is the C# code to get the OSArchitecture from the WMI interface.

My question is, why does it blow up on my Windows XP 64 bit install?
It appears to work fine under 64 bit Vista - I get a response of
either 32 bit or 64 bit as I would expect.
 
W

Willy Denoyette [MVP]

VistaDB said:
OK, I know this has been discussed before. I need to detect when I am
running on 64 bit windows, and write a specific key to the 32 bit node
for VS 2005 to load my plugin (I am 64 bit, it is 32 bit).

ManagementObjectSearcher mso = new ManagementObjectSearcher("SELECT *
FROM Win32_OperatingSystem"); //Win32_ComputerSystem");
ManagementObjectCollection qc = mso.Get();

Console.WriteLine("OSArchitecture: " +
mo["OSArchitecture"].ToString());

That is the C# code to get the OSArchitecture from the WMI interface.

My question is, why does it blow up on my Windows XP 64 bit install?

It "blows up" because, this property is only available on Vista and higher,
read the WMI docs in msdn before using it's class properties.
Note that it's not important to know whether you run on 64 or 32 bit OS,
what's important is to know whether you run a 64 bit application natively or
whether you run a 32 bit application under WOW64.
You can check whether you are running under wow64, by calling the
"IsWow64Process" API from Kernel32.dll via PInvoke. However, be carefull,
read the API description carefully, using this API can be tricky,.

Willy.
 
V

VistaDB

You can check whether you are running under wow64, by calling the
"IsWow64Process" API from Kernel32.dll via PInvoke. However, be carefull,
read the API description carefully, using this API can be tricky,.

I can't use that. I MUST be 100% managed - no DLL imports. Same app
runs under Mono right now and I don't want to break it just for this
silly call.
 
W

Willy Denoyette [MVP]

VistaDB said:
I can't use that. I MUST be 100% managed - no DLL imports. Same app
runs under Mono right now and I don't want to break it just for this
silly call.
There is no such thing like 100% managed, if you need to know certain
details about the underlying Windows platform you will have to call into
Win32, whether you are doing it yourself, or whether the framework exposes
this doesn't matter, you will have to transition into unmanaged code.
Anyway, this "silly" call is to only way to know whether you are running "32
bit" code on Windows 64-bit., and using WMI for this is no solution, mono
doesn't expose this.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top