Is there something in System.Environment that can tell me if the program is
running on a 64bit OS? What I am thinking is right now is to check the size
of IntPtr and if it is 4 then it is 32bit, but if it is 8 then it is 64bit.
Thanks,
Eric Renken 15 17307
Can you determine it from Environment.OSVersion.Version?
"Eric Renken" wrote:
Is there something in System.Environment that can tell me if the program is
running on a 64bit OS? What I am thinking is right now is to check the size
of IntPtr and if it is 4 then it is 32bit, but if it is 8 then it is 64bit.
Thanks,
Eric Renken
"Eric Renken" <Er********@newsgroup.nospamwrote in message
news:ex**************@TK2MSFTNGP05.phx.gbl...
Is there something in System.Environment that can tell me if the program
is running on a 64bit OS? What I am thinking is right now is to check the
size of IntPtr and if it is 4 then it is 32bit, but if it is 8 then it is
64bit.
No need to mess around with IntPtr: http://msdn2.microsoft.com/En-US/library/aa394239.aspx
If you're running on a 64-bit OS, the OSArchitecture property will return
"64-bit" as a string...
-- http://www.markrae.net
"Eric Renken" <Er********@newsgroup.nospamwrote:
Is there something in System.Environment that can tell me if the program
is running on a 64bit OS? What I am thinking is right now is to check the
size of IntPtr and if it is 4 then it is 32bit, but if it is 8 then it is
64bit.
If you're trying to figure out, "Is my app running in 32 or 64 bit mode?"
then IntPtr is the best way to go. That's how we do it in our applications,
and it works great.
If 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
( http://www.thescripts.com/forum/thread558929.html)
--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP http://www.coversant.com/blogs/cmullins
The only time I think it could be an issue is when running under 32-bit
mode, in which case, I would suspect IntPtr would be sized to 32 bits. If
the OP wants to get the platform regardless of which mode he is running
under, then the WMI way might be better.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:u4**************@TK2MSFTNGP06.phx.gbl...
No need to mess around with IntPtr: http://msdn2.microsoft.com/En-US/library/aa394239.aspx
What exactly is messy with checking IntPtr.Size? I can't think of
anything more straight forward. Call it premature optimization if you
want, but I also bet that it's significantly faster than anything
involving WMI.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
"Eric Renken" <Er********@newsgroup.nospamwrote in message
news:ex**************@TK2MSFTNGP05.phx.gbl...
Is there something in System.Environment that can tell me if the program
is running on a 64bit OS? What I am thinking is right now is to check the
size of IntPtr and if it is 4 then it is 32bit, but if it is 8 then it is
64bit.
Thanks,
Eric Renken
It's not that important to know whether you are running on 64 bit Windows,
what counts is whether you are running as a 64 bit or 32 bit application,
and the sizeof IntPtr is the right way to check this.
Willy.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:OI**************@TK2MSFTNGP06.phx.gbl...
The only time I think it could be an issue is when running under 32-bit
mode, in which case, I would suspect IntPtr would be sized to 32 bits. If
the OP wants to get the platform regardless of which mode he is running
under, then the WMI way might be better.
Exactly.
-- http://www.markrae.net
"Chris Mullins [MVP]" <cm******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
If you're trying to figure out, "Is my app running in 32 or 64 bit mode?"
then IntPtr is the best way to go. That's how we do it in our
applications, and it works great.
If 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.
-- http://www.markrae.net
"Mark Rae" <ma**@markNOSPAMrae.netwrote:
"Chris Mullins [MVP]" <cm******@yahoo.comwrote in message
>If 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 bit us during install - our installer is a 32 bit app, that pokes
around a bit then installs a 64 bit application. Everything worked great,
expect for the fact that it didn't work at all. Using WMI or using the size
of the IntPtr wouldn't have made any difference at all. The installer
correctly figured everything out, it was just unable to do what it needed to
do...
There are (I suspect) a number of other areas like this, although none
spring to mind immediatly. Well, ok, a few do - Mostly memory management
related, such as where the DLL's are mapped into the process space, where
the real Windows DLL's live in memory, I bet there are all sorts of Loader
and Rebasing differences, etc.
--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP http://www.coversant.com/blogs/cmullins
"Chris Mullins [MVP]" <cm******@yahoo.comwrote in message
news:Op*************@TK2MSFTNGP05.phx.gbl...
"Mark Rae" <ma**@markNOSPAMrae.netwrote:
>"Chris Mullins [MVP]" <cm******@yahoo.comwrote in message
>>If 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().Toke n))
// better add a manifest to your application if you end here ;-)
Willy.
What kind of software do you work on, that you know this kind of stuff off
the top of your head?
It's just... scary! (I mean that in the best possible way)
--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP http://www.coversant.com/blogs/cmullins
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:C2**********************************@microsof t.com...
"Chris Mullins [MVP]" <cm******@yahoo.comwrote in message
news:Op*************@TK2MSFTNGP05.phx.gbl...
>"Mark Rae" <ma**@markNOSPAMrae.netwrote:
>>"Chris Mullins [MVP]" <cm******@yahoo.comwrote in message If 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().Toke n))
// better add a manifest to your application if you end here
;-)
Willy.
Well I guess I should have been a little more clear on why I am asking. A
hardware manufacture Dallas Maxim is updating their USB 1-wire device to
work on 64 and 32 bit machines, and I will need to know what mode the OS is
running under so I can call the correct DLL in my code. I think I will
stick with the size of the IntPrt for now.
And actually right now I am working on some communication with a HID device
from C# and have a grand old time trying to get them to work in 64bit mode.
I have fixed some of the problems by replacing the Int32 in the definitions
with IntPtr.
My program itself doesn't care what architecture it is running on it all
those darn hardware devices I need to communicate with that are the pain.
Thanks everyone and I have learned some stuff about virtualation reading all
this.
Eric Renken
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:98**********************************@microsof t.com...
"Eric Renken" <Er********@newsgroup.nospamwrote in message
news:ex**************@TK2MSFTNGP05.phx.gbl...
>Is there something in System.Environment that can tell me if the program is running on a 64bit OS? What I am thinking is right now is to check the size of IntPtr and if it is 4 then it is 32bit, but if it is 8 then it is 64bit.
Thanks,
Eric Renken
It's not that important to know whether you are running on 64 bit Windows,
what counts is whether you are running as a 64 bit or 32 bit application,
and the sizeof IntPtr is the right way to check this.
Willy.
What kind of software do you work on, that you know this kind of stuff off
the top of your head?
It's just... scary! (I mean that in the best possible way)
I know for a fact that Willy wrote a large part of the CLR all by himself
and then sold it to MS. He is quite rich as well!
--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming... https://www.microsoft.com/MSPress/books/10933.aspx
OWC Black Book www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"Chris Mullins [MVP]" <cm******@yahoo.comwrote in message
news:uE**************@TK2MSFTNGP06.phx.gbl...
What kind of software do you work on, that you know this kind of stuff off
the top of your head?
It's just... scary! (I mean that in the best possible way)
--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP http://www.coversant.com/blogs/cmullins
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:C2**********************************@microsof t.com...
>"Chris Mullins [MVP]" <cm******@yahoo.comwrote in message news:Op*************@TK2MSFTNGP05.phx.gbl...
>>"Mark Rae" <ma**@markNOSPAMrae.netwrote: "Chris Mullins [MVP]" <cm******@yahoo.comwrote in message If 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().Toke n)) // better add a manifest to your application if you end here ;-)
Willy.
"Alvin Bruney [MVP]" <some guy without an email addresswrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>What kind of software do you work on, that you know this kind of stuff off the top of your head?
It's just... scary! (I mean that in the best possible way)
I know for a fact that Willy wrote a large part of the CLR all by himself
and then sold it to MS. He is quite rich as well!
--
Alvin, weren't you told this was highly confidential? Now I'll have to
invite all MVP's to a party on my yacht I guess :-)).
Willy.
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote
"Alvin Bruney [MVP]" <some guy without an email addresswrote:
>>What kind of software do you work on, that you know this kind of stuff off the top of your head?
It's just... scary! (I mean that in the best possible way)
I know for a fact that Willy wrote a large part of the CLR all by himself and then sold it to MS. He is quite rich as well!
Alvin, weren't you told this was highly confidential? Now I'll have to
invite all MVP's to a party on my yacht I guess :-)).
Well, in retrospect, I guess it's pretty obvious.
The first names are identical - William is both Willy or Bill.
It took me a bit to find the right anagram of Gates, but once I went
old-school ROT-13, ROT-47 and the original 1977 RSA algorithm (implemented
in BASIC) it was only a matter of time...
--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP http://www.coversant.com/blogs/cmullins This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mat |
last post by:
How can I detect when a link has been clicked but the new page is
still in the process of loading? The document.location.href property
still displays the current location (understandably) not the...
|
by: Doug R |
last post by:
Hello,
I could use a little help from you Gurus out there. I have an aplication
that watches a directory and detects when a PGP encrypted file lands in the
directory and starts a process that...
|
by: joebob |
last post by:
I've got two forms, Form1 and Form2. Form1 opens invisibly when the database opens. From Form1 (or from a regular module or class module accessed by Form1), is there a way to detect when Form2...
|
by: UJ |
last post by:
How do you detect when your session is going to timeout and display a
message saying 'unless you do something you will be logged out' much the way
bank web pages do?
Can you do it for the site...
|
by: Mike Stephens |
last post by:
I have an application to minimizes when X is clicked. If the user wants to
close the application they click the Exit Application button.This works fine
and does exactly what I need. I have since...
|
by: Eric Rupp via .NET 247 |
last post by:
I am designing a program that will detect when a computer becomes locked (screen saver comes on/Ctrl+Alt+Del).
I am looking to detect that and update a database for a custom Time Tracker program. ...
|
by: Rich |
last post by:
Hello,
I need to trap/detect when a textbox is entered via the tabkey. If the
textbox is not empty when entered via the tabkey then set focus to next
textbox. To enter that textbox would then...
|
by: Paul |
last post by:
Hello,
I have a datagridview with a checkbox in a column, and I want to detect
when the user change the value of the checkbox in the event
CheckedChanged, but I only detect that the value is...
|
by: Phil |
last post by:
I can check for MdiChildren.Length=0, but which event handler should I put
this in to detect when a child window is closed?
TIA
Phil.
|
by: john ciriello |
last post by:
Hi, I am trying to detect when the help window that pops up for a control
can be detected when it is closing. Right now when you click anywhere the
window closes but there does not seem to be...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
header("Location:".$urlback);
Is this the right layout the...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
| |