栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何以编程方式确定特定进程是32位还是64位

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何以编程方式确定特定进程是32位还是64位

我见过的一种更有趣的方式是:

if (IntPtr.Size == 4){    // 32-bit}else if (IntPtr.Size == 8){    // 64-bit}else{    // The future is now!}

要了解其他进程是否正在64位仿真器(WOW64)中运行,请使用以下代码:

namespace Is64Bit{    using System;    using System.ComponentModel;    using System.Diagnostics;    using System.Runtime.InteropServices;    internal static class Program    {        private static void Main()        { foreach (var p in Process.GetProcesses()) {     try     {         Console.WriteLine(p.ProcessName + " is " + (p.IsWin64Emulator() ? string.Empty : "not ") + "32-bit");     }     catch (Win32Exception ex)     {         if (ex.NativeErrorCode != 0x00000005)         {  throw;         }     } } Console.ReadLine();        }        private static bool IsWin64Emulator(this Process process)        { if ((Environment.OSVersion.Version.Major > 5)     || ((Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor >= 1))) {     bool retVal;     return NativeMethods.IsWow64Process(process.Handle, out retVal) && retVal; } return false; // not on 64-bit Windows Emulator        }    }    internal static class NativeMethods    {        [Dllimport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]        [return: MarshalAs(UnmanagedType.Bool)]        internal static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/576170.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号