博客
关于我
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安装crypto-js 如何安装crypto-js, python爬虫安装加解密插件 找不到模块crypto-js python报错解决丢失crypto-js模块
查看>>
npm安装教程
查看>>
npm报错Cannot find module ‘webpack‘ Require stack
查看>>
npm报错Failed at the node-sass@4.14.1 postinstall script
查看>>
npm报错fatal: Could not read from remote repository
查看>>
npm报错File to import not found or unreadable: @/assets/styles/global.scss.
查看>>
npm报错TypeError: this.getOptions is not a function
查看>>
npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
查看>>
npm淘宝镜像过期npm ERR! request to https://registry.npm.taobao.org/vuex failed, reason: certificate has ex
查看>>
npm版本过高问题
查看>>
npm的“--force“和“--legacy-peer-deps“参数
查看>>
npm的安装和更新---npm工作笔记002
查看>>
npm的常用操作---npm工作笔记003
查看>>
npm的常用配置项---npm工作笔记004
查看>>
npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
查看>>
npm编译报错You may need an additional loader to handle the result of these loaders
查看>>
npm设置淘宝镜像、升级等
查看>>
npm设置源地址,npm官方地址
查看>>
npm设置镜像如淘宝:http://npm.taobao.org/
查看>>
npm配置安装最新淘宝镜像,旧镜像会errror
查看>>