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

S

sajin

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
 
N

Newbie Coder

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
 
N

Newbie Coder

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
 
I

ImageAnalyst

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.
 
N

Newbie Coder

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
 
I

ImageAnalyst

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.)
 
S

sajin

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
 
N

Newbie Coder

That's cool - Nice Work

Newbie Coder

sajin said:
Hi All,

I got it through the registry entry

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

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

Thanks
 
C

Chris Mullins

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.
 
C

Chris Mullins

Using WMI may have far reaching implications.

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

Mudhead

What's wrong with this?

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

Newbie Coder

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
 
M

Mudhead

What??????????????????????
User never specified VB.NET 2005 code

Sure he did. Read his post below. I see VB.Net 2005 is listed there. Don't
you?
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
 
M

Mudhead

Opps...Ignore this post.

Mudhead said:
What's wrong with this?

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

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