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

你可能感兴趣的文章
Notepad++在线和离线安装JSON格式化插件
查看>>
notepad++最详情汇总
查看>>
notepad++正则表达式替换字符串详解
查看>>
notepad如何自动对齐_notepad++怎么自动排版
查看>>
Notes on Paul Irish's "Things I learned from the jQuery source" casts
查看>>
Notification 使用详解(很全
查看>>
NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
查看>>
NotImplementedError: Could not run torchvision::nms
查看>>
nova基于ubs机制扩展scheduler-filter
查看>>
Now trying to drop the old temporary tablespace, the session hangs.
查看>>
nowcoder—Beauty of Trees
查看>>
np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
查看>>
np.power的使用
查看>>
NPM 2FA双重认证的设置方法
查看>>
npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack‘解决方法
查看>>
npm ERR! ERESOLVE could not resolve报错
查看>>
npm ERR! fatal: unable to connect to github.com:
查看>>
npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
查看>>
npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
查看>>