Reputation: 43188
There is an enum of all supported processor architectures here: http://msdn.microsoft.com/en-us/library/system.reflection.processorarchitecture.aspx
Is there any way to determine which one corresponds to the running environment? System.Reflection.Assembly.GetExecutingAssembly().ProcessorArchitecture returns MSIL -- obviously wrong.
EDIT: Bojan Resnik posted an answer and deleted it. I see that some clarification is needed from the partial trace I got.
The assembly needs to run on multiple architectures and do different things based on what assembly instructions the running process accepts. Essentially, I need to select which version of a native DLL to load. I have one for each architecture.
Upvotes: 1
Views: 2163
Reputation: 86
You can use System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture for this. This was added to .NET in the .NET Framework 4.7.1.
Upvotes: 0
Reputation: 9645
P/Invoking GetSystemInfo is trivial from .Net and is much lighter weight than WMI. Also, it returns the architecture as seen by the process so on a x64 machine a WOW process will see x86 and a native process will see x64.
Upvotes: 2
Reputation: 46663
Here's a few WMI settings you may want to try. I don't have a 64-bit system handy at the moment, but it should be easy to check. Source code is below. Note that you may end up having to use a combination of calls (e.g. one to find wow, another to find native 32 vs. 64, etc.).
Also, check out http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/b1cfef99-5247-47c5-93d4-31eb6849df48 for some more discussion.
using System;
using System.Management;
class Program
{
static void Main(string[] args)
{
foreach (ManagementBaseObject o in new ManagementClass("Win32_OperatingSystem").GetInstances())
{
Console.WriteLine("Win32_OperatingSystem.OSArchitecture = " + o.Properties["OSArchitecture"].Value);
break;
}
foreach (ManagementBaseObject o in new ManagementClass("Win32_ComputerSystem").GetInstances())
{
Console.WriteLine("Win32_ComputerSystem.SystemType = " + o.Properties["SystemType"].Value);
break;
}
Console.ReadKey();
}
}
Upvotes: -1