博客
关于我
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/

你可能感兴趣的文章
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>