【小5聊】Winform窗体遍历进程提示拒绝访问以及32位无法访问64位模块解决方法

遍历进程,默认情况下窗体目标平台是勾选32位,以及没有以管理员程序运行,会出现拒绝访问

1、拒绝访问

2、 拒绝解决方法

  • 效果

  • 代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowTask
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            #region 必须以管理员身份启动(否则登录失败)
            //获得当前登录的Windows用户标示 
            if (!new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
            {
                //创建启动对象 
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                //设置运行文件 
                startInfo.FileName = System.Windows.Forms.Application.ExecutablePath;
                //设置启动动作,确保以管理员身份运行 
                startInfo.Verb = "runas";
                try
                {
                    //如果不是管理员,则启动UAC 
                    System.Diagnostics.Process.Start(startInfo);
                }
                catch { }

                //退出 
                System.Windows.Forms.Application.Exit();

                return;
            }
            #endregion

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FindFile());
        }
    }
}

3、进程32 位无法访问进程 64 位的模块

 

 4、进程32 位无法访问进程 64 位的模块 - 解决方法

  • 效果

  • 方法 

将目标平台设置为64位即可

猜你喜欢

转载自blog.csdn.net/lmy_520/article/details/121544046