How to determine Windows OS is 32-bit or 64-bit in .NET

Posted by Admin L in .NET Programming on 13-06-2011. Tags:

Author: Nosa Lee
Original Address: https://www.seeksunslowly.com/windows-os-bit-vb-net
To reprint this article, please indicate the source, thank you.
_____________________________________

Sometimes, we need to determine Windows OS is 32-bit or 64-bit.

Specifically, I want to load different DLL in 32-bit OS or 64-bit OS.

Through analysis and practice, I found a easy way to do this in .NET, just try the following code, it is tested OK in VB2008 + .NET 3.5 SP 1:

 

[cc lang=”vbnet”]
Dim platform$ = Nothing
platform$ = Environment.GetEnvironmentVariable(“ProgramFiles(x86)”)

If platform Is Nothing Then ‘ 32-bit.
Msgbox(“32-bit”)
Else
If platform.Length > 0 Then ‘ 64-bit.
MsgBox(“64-bit”)
Else ‘ 32-bit.
MsgBox(“32-bit”)
End If
End If
[/cc]

As you know, ONLY 64-bit Windows OSs have the “ProgramFiles(x86)” environment variable, so we can use it to determine Windows OS is 32-bit or 64-bit in .NET easily.

【赞赏 / Reward】

微信         支付宝         PayPal

Post a comment