Identifying the CPU architecture type using C#

2020-01-28 09:13发布

I want to check which CPU architecture is the user running, is it i386 or X64 or AMD64. I want to do it in C#. I know i can try WMI or Registry. Is there any other way apart from these two? My project targets .NET 2.0!

14条回答
在下西门庆
2楼-- · 2020-01-28 09:59

You could ask the user perhaps?

Just kidding of course... I think WMI is what you would use for that. But maybe there is some other way as well?

If you go for WMI then LinqToWmi could be of use. I tried it out once, and it seemed pretty straight forward =) -> http://www.codeplex.com/linq2wmi

查看更多
Root(大扎)
3楼-- · 2020-01-28 10:00

I know that this question is from the past, but as of 2017, there is now a simple method to know the architecture of the current process, in .net standard :

System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture

The value returned is one of X86, X64, ARM, ARM64 and gives the architecture of the process it's running in. OSArchitecture returns the architecture of the installed operating system instead.

Links to the docs (pretty useless though...):

RuntimeInformation.ProcessArchitecture: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.runtimeinformation.processarchitecture?view=netstandard-1.4

Architecture enumeration: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.architecture?view=netstandard-1.4

查看更多
登录 后发表回答