博客
关于我
C#如何以管理员身份运行程序
阅读量:268 次
发布时间:2019-03-01

本文共 517 字,大约阅读时间需要 1 分钟。

在WinForm程序中获取管理员权限:Win7及以上操作系统的配置方法

在使用WinForm程序时,若在Windows 7及以上版本操作系统运行,某些操作可能需要管理员权限才能执行成功。例如,通过程序调用CMD命令或访问Windows Service服务时,若未以管理员身份运行,可能会导致命令无效或无法访问服务。

本文将介绍如何配置WinForm程序以获取管理员权限。

首先,打开Visual Studio,进入项目的属性界面。在“解决方案资源管理器”中,右键点击项目名称,选择“属性”。在弹出的窗口中,找到“安全性”选项。

接下来,启用ClickOnce安全设置。这样可以确保程序在运行时具备必要的权限。

在项目目录下会生成一个新的文件“app.manifest”。打开该文件,找到以下代码段:

将上述代码修改为:

保存修改后,重新编译项目。在运行程序时,系统会提示“用户账户控制”来获取管理员权限。点击“是”以继续运行程序。

在编译过程中,记得关闭ClickOnce安全设置勾选项,以避免程序运行时出现错误。

通过以上配置,程序将能够以管理员身份运行,从而正常执行CMD命令或访问Windows Service服务。

转载地址:http://onex.baihongyu.com/

你可能感兴趣的文章
npm install 报错 no such file or directory 的解决方法
查看>>
npm install 权限问题
查看>>
npm install报错,证书验证失败unable to get local issuer certificate
查看>>
npm install无法生成node_modules的解决方法
查看>>
npm install的--save和--save-dev使用说明
查看>>
npm node pm2相关问题
查看>>
npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
查看>>
npm run build报Cannot find module错误的解决方法
查看>>
npm run build部署到云服务器中的Nginx(图文配置)
查看>>
npm run dev 和npm dev、npm run start和npm start、npm run serve和npm serve等的区别
查看>>
npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
查看>>
npm scripts 使用指南
查看>>
npm should be run outside of the node repl, in your normal shell
查看>>
npm start运行了什么
查看>>
npm WARN deprecated core-js@2.6.12 core-js@<3.3 is no longer maintained and not recommended for usa
查看>>
npm 下载依赖慢的解决方案(亲测有效)
查看>>
npm 安装依赖过程中报错:Error: Can‘t find Python executable “python“, you can set the PYTHON env variable
查看>>
npm.taobao.org 淘宝 npm 镜像证书过期?这样解决!
查看>>
npm—小记
查看>>
npm上传自己的项目
查看>>