How do I force my .NET application to run as administrator?
How do I force my .NET application to run as administrator?
You'll want to modify the manifest that gets embedded in the program. This works on Visual Studio 2008 and higher: Project + Add New Item, select "Application Manifest File". Change the <requestedExecutionLevel>
element to:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
The user gets the UAC prompt when they start the program. Use wisely; their patience can wear out quickly.
How do I make a console app always run as an administrator?
First, understand that there WILL BE a UAC dialog at some point in this process. There is no way to avoid it. There are a few approaches you can take:
- Have the people run the ERP software elevated. I am including this only for completeness. It is awful to have to consent to the UAC prompt every time you run the app when you usually don't need the powers. It would be a handy quick test, though, for you to confirm that if your app is elevated, things will work. Everything launched from an elevated process is elevated, so if your app still gets the error message, this isn't something you'll fix by elevating.
- Change the code in the ERP app to launch your app elevated. You mention C#. Launching with the
runas
verb is an approach here. This puts the burden on the ERP developer and they may not be able to do it. - Add a manifest to your app. You can embed one, or if your app is called foo.exe just hand-create a foo.exe.manifest file with the appropriate requestedExecutionLevel. To embed one, use the Properties page of your C# project to choose the right kind of manifest. Make sure you're launched with
UseShellExecute
set to true, or the manifest will be ignored.
If you choose the first option, the UAC prompt will be every time the ERP app launches. Not good. If you choose the second or third, the UAC prompt will be every time your console app is launched from the ERP app. Probably acceptable.
One other thing you might consider is looking far more seriously into why the console app needs admin privs. Are you writing to the root of C or to Program Files? Are you updating a registry key in HKLM? Whatever you're doing, why are you doing it that way? Unless your app installs or configures something (in which case getting a UAC prompt is good and proper) you should try to adapt it so that it writes to pre-user storage and doesn't need elevation. Then you will no longer be worrying about how to launch it elevated, in any case.
How do I force my .NET application to run as administrator?的更多相关文章
- 错误处理:error(0) error portability:3 this xilinx application has run out of memory has encountered a memory conflict
在FPGA侧提供了一个gp0,gp1各占1m内存的版本后.生成mcs版本,在下载版本时报错: error(0) error portability:3 this xilinx application ...
- "Sorry this application cannot run under a virtual machine" Error
错误: 运行一个程序是出现了 “sorry this application cannot run under a virtual machine” 错误. 如何解决: 控制面板-->卸载程序- ...
- 关闭Hyper-V后,天翼校园宽带(Netkeeper)依旧显示Sorry, this application cannot run under a Virtual Machin的解决方法
环境: win10专业版,版本1909 经过: 尝试了一下win10 更新后的沙盒系统,当时开启了沙盒,但是未打开Hyper-V,沙盒正常运行. 第二次开机后天翼校园宽带(Netkeeper)显示So ...
- [NativeScript] Create new application and run emulator
Install: npm i -g nativescript Create: tns create <app_name> --ng Run: tns emulate ios List al ...
- Arcmap软件报错:This application cannot run under a virtual machine arcmapr, 但是你并没有使用虚拟机
在任务栏搜索"启用或关闭 windows 功能",取消 "适用于 Linux 的 Windows 子系统" (有可能还需要 取消 "虚拟机平台&quo ...
- 创建Windows Service
基本参照使用C#创建Windows服务,添加了部分内容 目录 创建Windows Service 可视化管理Windows Service 调试 示例代码 创建Windows Service 选择C# ...
- Elevated privileges for Delphi applications
BY CRAIG CHAPMAN · PUBLISHED 2015-06-08 · UPDATED 2015-06-08 One of my customers recently asked th ...
- Installing Fonts programatically C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- [转载]解决clickonce不支持administer权限问题
转自ClickOnce deployment vs. requestedExecutionLevel = requireAdministrator ClickOnce方式部署应用简单方便,估计很多人都 ...
随机推荐
- python中的encode()和decode()函数
前言: 我们知道,计算机是以二进制为单位的,也就是说计算机只识别0和1,也就是我们平时在电脑上看到的文字,只有先变成0和1,计算机才会识别它的意思.这种数据和二进制的转换规则就是编码.计算机的发展中, ...
- 回复git@vger.kernel.org的注意事项
比如回复这封邮件 https://public-inbox.org/git/db2dcf54-8b1c-39b1-579c-425ef158c6a1@kdbg.org/ Reply instructi ...
- spring cloud gateway 拦截request Body
在接入Spring-Cloud-Gateway时,可能有需求进行缓存Json-Body数据或者Form-Urlencoded数据的情况. 由于Spring-Cloud-Gateway是以WebFlux ...
- MDX members使用
Members (Set) 函数返回该指定层次结构内所有成员(不包括计算成员)的集: Members (String) 函数返回已指定名称的单个成员. 通常,将 Members (String) 函数 ...
- <转>Excel生成guid、uuid
Excel生成guid.uuid 原文地址:https://www.cnblogs.com/jory/p/7718305.html 1.Excel生成guid,uuid 格式:600d65bc- ...
- MYSQL 使用存储过程批量更新表数据
功能:实现将表result_good_city_dzl中的字段lat更新为表 result_good_city_lh中的lat,条件是两个表中的id一样 即: update result_good_c ...
- Oracle数据库(一)--Oracle简介及安装
一.Oracle简介 Oracle是美国一家著名的软件公司,也是世界上排名前三的软件公司(微软,Oracle,Adobe).Oracle数据库是一个大型的关系型数据库,在一些大型的企业之中使用的会比较 ...
- flink批处理中的source以及sink介绍
一.flink在批处理中常见的source flink在批处理中常见的source主要有两大类: 1.基于本地集合的source(Collection-based-source) 2.基于文件的sou ...
- 原生AJAX的封装
/**调用AJAX ajaxPlug.openajax({ url: "./TestXHR.aspx", //请求地址 type: "POST", //请求方式 ...
- linux 服务器,登录出现login incorrect
1.排查是否是登录用户的密码错误 2.查看本机电脑键盘是否有误 3.排查是否是服务器目录全是777权限 注意事项: 原因是您把系统中全部文件的权限改为的777 ,权限混乱,虽然现在可以访问,但是其他文 ...