Re: Detect when in 64bit OS
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Fri, 1 Jun 2007 12:33:50 +0200
"Chris Mullins [MVP]" <cmullins@xxxxxxxxx> wrote in message news:OpbzC19oHHA.716@xxxxxxxxxxxxxxxxxxxxxxx
"Mark Rae" <mark@xxxxxxxxxxxxxxxxx> wrote:"Chris Mullins [MVP]" <cmullins@xxxxxxxxx> wrote in messageIf you're trying to figure out, "Am I running in 32 bit mode on a 64 bit machine?" then things are a bit harder. For instance, it bit us in an installer which did some registry settings stuff, and ended up with Windows-On-Windows issues
That's exactly right, which is why WMI is the right way to do it.
I think you misunderstood what I meant. Telling which OS and which architecture you're running on are pretty easy, really. Knowing what to do with that data is pretty hard.
For example, if you write to the registry from a 32 bit app, then try to read back the same key in a 64 bit app, you'll get totally different data. This is due to the Wow6432Node, which does some tricky things that you just have to know about.
This is the result of the "virtualization" of the registry, done when running "legacy" 32 bit interactive applications under WOW64.
64 bit applications never run virtualized, nor do 32 or 64 bit services and drivers.
Disabling "virtualization" will be done by default when using the Orcas csharp compiler (and with the upcomming SP1 of Framework V2), pre-Orcas CSC buids should include a manifest by running mt.exe in order to disable "virtualization".
You can check whether "virtualization" is effective by inspecting the access token of the current (non-impersonating) user like this:
[DllImport("advapi32.dll", EntryPoint = "GetTokenInformation", SetLastError = true)]
static extern bool GetTokenInformationNative(
IntPtr TokenHandle,
int TokenInformationClass,
ref int TokenInformation,
int TokenInformationLength,
out int ReturnLength);
public bool IsVirtualized(IntPtr token)
{
bool virtualized = false;
int len = 4;
int info = 0;
if (!GetTokenInformationNative(token, 24, ref info, len, out len)) // 24 = TokenVirtualizationEnabled
{
string s = "Win32 error " + Marshal.GetLastWin32Error().ToString();
throw new Exception(s);
}
if(info != 0)
virtualized = true;
return virtualized;
}
// usage...
if(IsVirtualized(WindowsIdentity.GetCurrent().Token))
// better add a manifest to your application if you end here ;-)
Willy.
.
- Follow-Ups:
- Re: Detect when in 64bit OS
- From: Chris Mullins [MVP]
- Re: Detect when in 64bit OS
- References:
- Re: Detect when in 64bit OS
- From: Mark Rae
- Re: Detect when in 64bit OS
- From: Chris Mullins [MVP]
- Re: Detect when in 64bit OS
- Prev by Date: Re: what does StructLayoutAttribute.Pack do!??
- Next by Date: Re: what does StructLayoutAttribute.Pack do!??
- Previous by thread: Re: Detect when in 64bit OS
- Next by thread: Re: Detect when in 64bit OS
- Index(es):
Relevant Pages
|