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方式部署应用简单方便,估计很多人都 ...
随机推荐
- Codeforces 510C (拓扑排序)
原题:http://codeforces.com/problemset/problem/510/C C. Fox And Names time limit per test:2 seconds mem ...
- taintCheck的实现
参考:http://bitblaze.cs.berkeley.edu/papers/taintcheck-full.pdf 1. 应用taint analysis需要解决三个问题 a. 哪些input ...
- C# 获取微信小程序access_token
/// <summary> /// 获取access_token /// </summary> /// <returns></returns> publ ...
- static_cast关键字 dynamic_cast关键字
前言 说起C++中的继承.多态.虚函数等概念,可能很多同学都有所了解,但是要说真正熟知的同学可能就不是很多了.最近在编程过程中了解到C++类型的层次转换(这就涉及到了多态和继承的相关概率),通常C语言 ...
- ctDNA的分析理论上也可以为多样性的肿瘤
导语 肺腺癌(LUAD)和肺鳞癌(LUSC)是最常见的非小细胞肺癌类型.循环肿瘤DNA(ctDNA)是由凋亡或坏死的肿瘤细胞释放并在血液中循环的小片段DNA.与常规肿瘤活检相比,ctDNA检测具有一定 ...
- php分割url,获取参数query
#测试网址: http://localhost/blog/testurl.php?id=5 //获取域名或主机地址echo $_SERVER['HTTP_HOST']."<br> ...
- linux缺頁異常處理--內核空間[v3.10]
缺頁異常被觸發通常有兩種情況—— 1.程序設計的不當導致訪問了非法的地址 2.訪問的地址是合法的,但是該地址還未分配物理頁框 下面解釋一下第二種情況,這是虛擬內存管理的一個特性.盡管每個進程獨立擁有3 ...
- VS进程附加的使用
一,附加进程(ctrl+alt+p)调试本地服务器接口(WCF,webapi等)的api 1>接口(WCF,webapi等)的api发布到本地IIS服务器,然后使用附加进程,将你发布的IIS添加 ...
- linux基本命令的简单介绍
基本命令 man:查看帮助信息 :一般系统命令太多,要记住这些命令是不可能的,man是一个联机帮助信息 man提供大量的帮助信息,一般分为以下4各部分 NAME:对命令的简单介绍 SYNOPSIS对命 ...
- 迷你redux实现,redux是如何进行实现的?
export function createStore(reducer){ let currentState={} let currentListeners=[] function getState( ...