[转载]解决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 ...
随机推荐
- Oracle 完全理解connect by-详细脚本-可实战
狒狒Q971751392 未来星开发团队--狒狒(QQ:9715234) oracle树查询的最重要的就是select…start with…connect by…prior语法了.依托于该语法,我们 ...
- 【数据结构】 List 简单实现
public class XList<T> : IEnumerable, IEnumerator { #region List 简单实现 /// <summary> /// 存 ...
- ProxySQL读写分离测试(续)
Preface I've implemented ProxySQL on PXC yesterday but got some errors when configured query ...
- 利用selenium自动化登录淘宝
#encoding=utf-8 from selenium import webdriver from selenium.webdriver.common.action_chains import A ...
- 孤荷凌寒自学python第六十九天学习并实践beautifulsoup对象用法2
孤荷凌寒自学python第六十九天学习并实践beautifulsoup对象用法2 (完整学习过程屏幕记录视频地址在文末) 今天继续学习beautifulsoup对象的属性与方法等内容. 一.今天进一步 ...
- packstack安装ironic
KVM Centos7.3虚机 安装openstack Pike版本, 其它版本安装方法类似. packstack目前对NetworkManager 还不支持,我们修改下配置: systemctl d ...
- MySQL统计数据库表大小
use information_schema; SELECT TABLE_NAME, (DATA_LENGTH/1024/1024) as DataM , (INDEX_LENGTH/1024/102 ...
- spring mvc:实现给Controller函数传入map参数
[1]前端js调用示例: ...fillOrDiffer?inMapJson={"2016-08-31 0:00:00":0.1,"2016-08-31 0:15:00& ...
- Uva 294 Divisors(唯一分解定理)
题意:求区间内正约数最大的数. 原理:唯一分解定义(又称算术基本定理),定义如下: 任何一个大于1的自然数 ,都可以唯一分解成有限个质数的乘积 ,这里 均为质数,其诸指数 是正整数.这样的分解称 ...
- 【iOS开发】initWithNibName、initWithCoder、awakeFromNib和 loadNibNamed详解
第一.initWithNibName这个方法是在controller的类在IB中创建,但是通过Xcode实例化controller的时候用的. 第二.initWithCoder 是一个类在IB中创建但 ...