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方式部署应用简单方便,估计很多人都 ...
随机推荐
- static、final修饰的变量和方法能否被继承的问题
首先定义父类和子类 public class Parent { protected static String a = "static"; final String b = &qu ...
- 【c#技术】一篇文章搞掂:Newtonsoft.Json Json.Net
一.介绍 Json.Net是一个.Net高性能框架. 特点和好处: 1.为.Net对象和JSON之间的转换提供灵活的Json序列化器: 2.为阅读和书写JSON提供LINQ to JSON: 3.高性 ...
- nRF51822学习笔记 之 blinky_example
使用的开发板是nRF51822 AK II,爱板网做活动买的. 开发资料可以去这里下载:链接: http://pan.baidu.com/s/1f8pD8 密码: 741y
- java并发编程笔记(七)——线程池
java并发编程笔记(七)--线程池 new Thread弊端 每次new Thread新建对象,性能差 线程缺乏统一管理,可能无限制的新建线程,相互竞争,有可能占用过多系统资源导致死机或者OOM 缺 ...
- T1373:鱼塘钓鱼(fishing)
原题链接:1373:鱼塘钓鱼(fishing) 解题思路: 由于在走路时,鱼的数量不会减少,那我们此时可以先减去路上可能花掉的时间,用剩下的时间来找最多的鱼,然后从左向右走,k枚举能到达的最远的鱼塘, ...
- MSF——Payload模块(二)
MSF系列: MSF——基本使用和Exploit模块(一) MSF——Payload模块(二) MSF——Meterpreter(三) MSF——信息收集(四) 一.exploit和payload e ...
- SpringMVC学习(10):异常处理
在项目中如何处理出现的异常,在每个可能出现异常的地方都写代码捕捉异常?这显然是不合理的,当项目越来越大是也是不可维护的.那么如何保证我们处理异常的代码精简且便于维护呢?这就是本篇要讲的内容->异 ...
- VMware Converter Standalone迁移概要
VMware Converter 迁移工具使用:1.基本概念 1.1基本组件: converter standalone server:包含server和worker两个服务,这两个服务经常一起安装 ...
- 禁用usb是否一种方法?
CM_Request_Device_EjectW?? ddk sdk必须安装 https://blog.csdn.net/phmatthaus/article/details/49779585
- [HTML知识体系]语义化标签概论
1.什么是语义化 语义化(Semantic)在HTML5中被大量提起,就是语义化标签向浏览器和开发者展示了它所包裹内容的类型与意思,可是至今我看了好多代码,HTML5新增的语义化标签的使用率还是挺低的 ...