[转载]解决clickonce不支持administer权限问题
转自ClickOnce deployment vs. requestedExecutionLevel = requireAdministrator
ClickOnce方式部署应用简单方便,估计很多人都用过,但这种方式存在一定的“缺陷”,即以管理员方式启动应用的问题,虽然出于安全考虑可以理解,但给需要管理员权限才能正常运行的程序带来了一定的麻烦,这导致部分人员放弃了ClickOnce发布。
经过查找相关资料,发现还是有办法解决这个问题的,具体操作如下:
1、保留manifest文件不变。
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
2、然后编辑Program.cs文件如下:
using System;
using System.Diagnostics;
using System.Reflection;
using System.Security.Principal;
using System.Windows.Forms; namespace MyProgramNamespace
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
var wi = WindowsIdentity.GetCurrent();
var wp = new WindowsPrincipal(wi); bool runAsAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator); if (!runAsAdmin)
{
// It is not possible to launch a ClickOnce app as administrator directly,
// so instead we launch the app as administrator in a new process.
var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase); // The following properties run the new process as administrator
processInfo.UseShellExecute = true;
processInfo.Verb = "runas"; // Start the new process
try
{
Process.Start(processInfo);
}
catch (Exception)
{
// The user did not allow the application to run as administrator
MessageBox.Show("Sorry, but I don't seem to be able to start " +
"this program with administrator rights!");
} // Shut down the current process
Application.Exit();
}
else
{
// We are running as administrator
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
}
也可参考《以管理员身份启动ClickOnce部署的应用程序》,不过该文章方法我没有调试成功,主要是我C#基础不行。
开机自启动解决权限问题,也可参考《VS编写程序主动要求系统管理员权限(UAC控制)》和《Win7如何提升为管理员权限,如何开机启动需要管理员权限的程序,解决Win7开机不能自动运行的问题等》
[转载]解决clickonce不支持administer权限问题的更多相关文章
- c# 解决IIS写Excel的权限问题
c# 解决IIS写Excel的权限问题 from: http://www.jb51.net/article/31473.htm 发布:mdxy-dxy 字体:[增加 减小] 类型:转载 使用以上方法必 ...
- jquery easyui-linkButton获取和设置按钮text并且解决火狐不支持innerText的方法
<a href="javascript:test" id="btn" class="easyui-linkbutton" iconCl ...
- 解决ie6不支持position: fixed;导致无法滚动的办法
<div id="im" style="top: 100px; position: fixed; left: 5px; border: 3px solid #006 ...
- 解决selenium不支持firefox低版本的问题
解决selenium不支持firefox低版本的问题 在火狐浏览器升级后,突然发现webdriver运行脚本的时候不能调出火狐浏览器了,并报错WebDriverException:Message:'C ...
- 解决IE8不支持console
解决IE8不支持console,代码中包含console时会报错. //解决 IE8 不支持console window.console = window.console || (function ( ...
- 解决ClickOnce签名过期问题(转载)
原文地址:http://www.cnblogs.com/xuhaibiao/archive/2009/06/23/1509692.html 场景:用于生产环境的项目进行系统升级,在发布ClickOnc ...
- 解决IE6不支持position:fixed;的问题
在网页设计中,时常要用到把某个元素始终定位在屏幕上,即使滚动浏览器窗口也不会发生变化. 一般我们会使用position:fixed来进行绝对固定,但IE6并不支持position:fixed属性,所以 ...
- 解决firefox不支持-webkit-line-clamp属性
转载声明: 请注明本文引用自http://www.cnblogs.com/guolizhi/ css中-webkit-line-clamp这个属性表示超过指定行的文本隐藏并且会在结尾加上...号,用起 ...
- [转载]解决"command 'gcc' failed with exit status 1"错误问题
转自:https://blog.csdn.net/learn_tech/article/details/80066583 解决"command 'gcc' failed with exit ...
随机推荐
- python 快速搭建文件服务器
以http方式共享当前文件夹的文件 可实现跨平台文件传输 只需要一句话搞定 #python -m SimpleHTTPServer 8001 浏览器中输入 http://ip:8001 显示所有文件 ...
- js滚动及可视区域的相关的操作
element.getBoundingClientRect 判断指定元素相对于页面可视窗口的位置信息,通常结合windows.onScroll方法使用,当element.getBoundingClie ...
- tomcat 异常
Removing obsolete files from server... Could not clean server of obsolete files: null java.lang.Null ...
- 讨伐Cucumber行为驱动
Cucumber行为驱动,简称BDD,其核心思想是把自然语言转换成代码:但在敏捷开发的过程中,这种东西极大的束缚了测试人员的手脚,感觉它像封建时代的八股文,要遵守严格的韵律,反正我个人十分反感:就像在 ...
- 数据库学习(四)with as (补充 nvl 和 count 函数)
with as 的专业解释我这就不详细说明了,我这就梳理下我自己的实践应用,就是根据某个条件查询出结果集放在一个临时表里面,可以创建多个临时表,然后再从这些临时表中查询出要的数据. 参考资料:http ...
- Django数据模型--字段详解
一.字段 1.CharField: 字段数据类型为字符串 class Test(models.Model): test = models.CharField(max_length=) 2.Intege ...
- 文件特殊权限:SUID,SGID,SBIT
我们之前认识的文件的权限仅局限于r,w,x,但如果我们执行命令“ll /tmp; ll /usr/bin/passwd”,会出现除了r,w,x之外的其他字母: 即出现了特殊权限(s跟t). [SetU ...
- windows2008 R2 系统 安装wampserver提示“缺少msvcr110.dll文件”处理办法
windows2008 R2 系统 安装wampserver提示“缺少msvcr110.dll文件”处理办法 原因分析: 因缺少Visual C++ Redistributable for Visua ...
- Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/xxx项目名]]
可能是web.xml中的一些配置导致Tomcat启动失败,把web.xml中除 <welcome-file-list>外的全部配置删除后,就能正常启动Tomact了. 具体什么原因还不清楚 ...
- 【历史】- .NET之父 - Anders Hejlsberg
简介 安德斯·海尔斯伯格(Anders Hejlsberg,1960.12~),丹麦人,Turbo Pascal编译器的主要作者,Delphi和.NET之父! 安德斯·海尔斯伯格曾在丹麦技术大学学习工 ...