How to detect Windows 64-bit platform with .NET?

前端 未结 29 3425
野性不改
野性不改 2020-11-22 04:53

In a .NET 2.0 C# application I use the following code to detect the operating system platform:

string os_platform = System.Environment.OSVersion.Platform.ToS         


        
29条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 05:19

    Here is the direct approach in C# using DllImport from this page.

    [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] 
    [return: MarshalAs(UnmanagedType.Bool)] 
    public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo); 
    
    public static bool Is64Bit() 
    { 
        bool retVal; 
    
        IsWow64Process(Process.GetCurrentProcess().Handle, out retVal); 
    
        return retVal; 
    } 
    

提交回复
热议问题