Geeks With Blogs

News

qrcode

Lance Robinson

Create Your Badge

Lance Robinson is a software engineer in Durham, Chapel Hill, Raleigh, and surrounding areas. More about Lance.

 Subscribe


Lance's TextBox » About Me » My Resume »Twitter

Easy a pie:

function is64bit() {
if ([IntPtr].Size -eq 4) { return $false }
else { return $true }
}

Explanation: the size of an IntPtr will be 4 bytes on a 32 bit machine and 8 bytes on a 64 bit machine.

I came across the tip somewhere (blog, usenet??) but I couldn't find it again - so I thought I'd share it here for anybody else who is looking for it.

Technorati Tags:
Posted on Friday, February 20, 2009 10:21 AM Programming , PowerShell | Back to top


Comments on this post: PowerShell function to determine if running on 64 bit machine

# re: PowerShell function to determine if running on 64 bit machine
Requesting Gravatar...
Here's a shorter variant:

function Is64Bit
{
[IntPtr]::Size -eq 8
}

Left by Martin on Feb 20, 2009 12:00 PM

# re: PowerShell function to determine if running on 64 bit machine
Requesting Gravatar...
Just to clarify - this will still return false if you're running in a 32 bit process on a 64 bit machine!
Left by Lance Robinson on May 21, 2009 5:11 PM

# re: PowerShell function to determine if running on 64 bit machine
Requesting Gravatar...
Hi there, I wrote the OSArchitecture PowerShell function to always get the correct bit width of the OS, even when you are running in a 32 bits process on a 64 bits machine (i.e. under WoW64).

See http://vincenth.net/blog/archive/2009/11/02/detect-32-or-64-bits-windows-regardless-of-wow64-with-the-powershell-osarchitecture-function.aspx
Left by Vincent Hoogendoorn on Nov 02, 2009 10:20 PM

Your comment:
 (will show your gravatar)


Copyright © Lance Robinson | Powered by: GeeksWithBlogs.net