How I can find out on which platform I am running (32/64 bits)?

How I can find out on which platform I am running (32/64 bits)?

Post by saji » Sat, 23 Dec 2006 15:03:22


Hi All,

I am building a windows application in VB .Net 2005 , and for deploying
the application i need to run some exe's if it is 32 bits and some
other exe's for 64 bits

Can anyone tell me how can i findout this using VB .Net


Thanks in advance
-Sajin
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by Newbie Cod » Sat, 23 Dec 2006 21:33:13

I don't have the code for you, but you will need to use the GetVersionEx API
with the OSVERSIONINFOEX Structure

Use the Environment namespeace to get the basic OS version
( http://www.yqcomputer.com/ ://support.microsoft.com/k
b/304722/en-us) & pass to the above API

You can then find out if its a server/workstation/service pack level...

I hope this is of some use

Newbie Coder

 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by ImageAnaly » Sun, 24 Dec 2006 00:58:17

Some sample code is here:
http://www.yqcomputer.com/
on Planet Source Code. It's VB6 though. I don't know of anything in
vb.net to get that - there may be, but I personally am just unaware of
any.
Regards,
ImageAnalyst
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by Newbie Cod » Sun, 24 Dec 2006 02:54:13

But with the PSC screen from that code you see that it says things like
Professional/home... That isn't actually breaking it down far enough, is it?
Only the 64 bit is of use there though.

Lets rip the code to pieces & see if we can do a simple translation. Need to
get my VS 6 Enterprise discs out 'cos the upgrade feature in VB.NET ain't
all that, is it?

Newbie Coder
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by Newbie Cod » Sun, 24 Dec 2006 04:04:01

Ok. So here is the answer

'IsWow64Process' API function is declared in Kernall32.dll from XP onwards

' Import
Imports System.Diagnostics

' Declaration
Private Declare Function IsWow64Process Lib "kernel32" (ByVal hProcess As
Int32, ByRef Wow64Process As Boolean) As Int32

' Function
Private Function Is64Bit() As Boolean
Dim proc As Process = Process.GetCurrentProcess
Dim Wow64Process As Boolean
Try
Return IsWow64Process(proc.Id, Wow64Process) <> 0
Catch ex As Exception
Return False
End Try
End Function

' Usage:
MessageBox.Show(Is64Bit.ToString)

I hope this helps,

Newbie Coder
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by ImageAnaly » Mon, 25 Dec 2006 04:48:00

You didn't look at the whole screenshot. Look at the next line below
the professional/home. It says "64 bit system: False". Presumably it
would say true if you had a 64 bit system, so there must be a way in
the code to detect that.
ImageAnalyst.
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by Newbie Cod » Mon, 25 Dec 2006 10:46:04

I saw that, downloaded the VB 6 code, updated it to VB.NET & posted above
your last post

Please read my last post before this one

Newbie Coder
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by ImageAnaly » Wed, 27 Dec 2006 23:52:23

Good! Nice contribution! I'm sure it will be useful to many in the
future as 64 bit systems become more commonplace.
ImageAnalyst.
(By the way, your prior post wasn't there when I replied via Google
Discussion Groups even though you posted it a day before mine. Maybe
there is a lag somewhere.)
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by saji » Sat, 30 Dec 2006 17:14:55

Hi All,

I got it through the registry entry

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\Environment
Read the Key value "PROCESSOR_ARCHITECTURE"

For 32bit it shows - x86
For 64bit it shows- AMD64

Thanks
Sajin
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by Newbie Cod » Sun, 31 Dec 2006 02:34:20

That's cool - Nice Work

Newbie Coder



HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\Environme
nt


above
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by Chris Mull » Sun, 31 Dec 2006 04:23:07

There are all these complex answers that I see people giving. There's a much
easier way:

public static bool IsRunningOnWin64()
{
return (IntPtr.Size == 8);
}

In VB this would be:

public shared function IsRunningOnWin64() as boolean
return (IntPtr.Size = 8)
end function

This won't tell you if you're running in WOW on Win64, but it'll let you
know if your app is running in 32 or 64 bit land.
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by Chris Mull » Sun, 31 Dec 2006 08:13:57

Using WMI may have far reaching implications.

I believe that a limited access account won't have sufficient right to run
the WMI select.
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by Mudhea » Sun, 31 Dec 2006 12:08:55

What's wrong with this?

Debug.WriteLine(My.Computer.Info.OSFullName)
Debug.WriteLine(My.Computer.Info.OSPlatform)
Debug.WriteLine(My.Computer.Info.OSVersion)
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by Newbie Cod » Sun, 31 Dec 2006 12:35:11

User never specified VB.NET 2005 code
 
 
 

How I can find out on which platform I am running (32/64 bits)?

Post by Newbie Cod » Sun, 31 Dec 2006 12:46:24

Found another way for you using WMI:

Add a reference to the SYSTEM.MANAGEMENT.DLL

Then add this Import:

' Import

Imports System.management

' Add a Textbox called 'txtSystemType' & a button called 'btnGet'. Now paste
in the following code:

Dim mos As ManagementObjectSearcher = New
ManagementObjectSearcher("SELECT * FROM Win32_Processor")
Dim mo As ManagementObject

Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGet.Click
For Each mo In mos.Get
txtSystemType.Text = mo("AddressWidth").ToString & " bit"
Next
End Sub

This will then return 32 or 64 & 'bit' to the textbox

I hope this also helps,

Newbie Coder