473,548 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detect when in 64bit OS

Is there something in System.Environm ent 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
May 31 '07 #1
15 17417
Can you determine it from Environment.OSV ersion.Version?

"Eric Renken" wrote:
Is there something in System.Environm ent 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
May 31 '07 #2
"Eric Renken" <Er********@new sgroup.nospamwr ote in message
news:ex******** ******@TK2MSFTN GP05.phx.gbl...
Is there something in System.Environm ent 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

May 31 '07 #3
>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.
May 31 '07 #4
"Eric Renken" <Er********@new sgroup.nospamwr ote:
Is there something in System.Environm ent 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
May 31 '07 #5
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.co m

"Mattias Sjögren" <ma************ ********@mvps.o rgwrote in message
news:u4******** ******@TK2MSFTN GP06.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.

May 31 '07 #6
"Eric Renken" <Er********@new sgroup.nospamwr ote in message
news:ex******** ******@TK2MSFTN GP05.phx.gbl...
Is there something in System.Environm ent 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.

May 31 '07 #7
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:OI******** ******@TK2MSFTN GP06.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

May 31 '07 #8
"Chris Mullins [MVP]" <cm******@yahoo .comwrote in message
news:%2******** ********@TK2MSF TNGP02.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

May 31 '07 #9
"Mark Rae" <ma**@markNOSPA Mrae.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
May 31 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
13510
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 one that's about to load. I have a page that reloads every 30 seconds in order to access live data. If a user clicks on a link just prior to the...
4
3711
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 decrypts it and parses the resulting contents. I am using the FileSystemWatcher's Created event to detect when the file arrives. The problem I have...
6
2654
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 opens? I'm restricted to only coding in Form1 (or a regular module or class module accessed by Form1). The code can't be in another Form's module, and...
3
1431
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 or do you need to put code on every page doing it? TIA
2
19926
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 discovered it is holding Windows open when you shutdown. If the application is running and the user shutsdown Window it holds up everything. If the...
1
1627
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. Much the same way Windows Messanger will update a person's status to Away when their computer locks. Anyone ever come across the code for this? ...
2
1711
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 require a mouseclick if it already contains text to be edited. I am guessing that I would need to trap for this in the Enter Event of this...
0
1344
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 changed when the focus is in another column. An idea? Thanks
12
6216
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.
0
1075
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 anyway to detect it. Thanks.
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7803
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6036
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3495
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.