转自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权限问题的更多相关文章

  1. c# 解决IIS写Excel的权限问题

    c# 解决IIS写Excel的权限问题 from: http://www.jb51.net/article/31473.htm 发布:mdxy-dxy 字体:[增加 减小] 类型:转载 使用以上方法必 ...

  2. jquery easyui-linkButton获取和设置按钮text并且解决火狐不支持innerText的方法

    <a href="javascript:test" id="btn" class="easyui-linkbutton" iconCl ...

  3. 解决ie6不支持position: fixed;导致无法滚动的办法

    <div id="im" style="top: 100px; position: fixed; left: 5px; border: 3px solid #006 ...

  4. 解决selenium不支持firefox低版本的问题

    解决selenium不支持firefox低版本的问题 在火狐浏览器升级后,突然发现webdriver运行脚本的时候不能调出火狐浏览器了,并报错WebDriverException:Message:'C ...

  5. 解决IE8不支持console

    解决IE8不支持console,代码中包含console时会报错. //解决 IE8 不支持console window.console = window.console || (function ( ...

  6. 解决ClickOnce签名过期问题(转载)

    原文地址:http://www.cnblogs.com/xuhaibiao/archive/2009/06/23/1509692.html 场景:用于生产环境的项目进行系统升级,在发布ClickOnc ...

  7. 解决IE6不支持position:fixed;的问题

    在网页设计中,时常要用到把某个元素始终定位在屏幕上,即使滚动浏览器窗口也不会发生变化. 一般我们会使用position:fixed来进行绝对固定,但IE6并不支持position:fixed属性,所以 ...

  8. 解决firefox不支持-webkit-line-clamp属性

    转载声明: 请注明本文引用自http://www.cnblogs.com/guolizhi/ css中-webkit-line-clamp这个属性表示超过指定行的文本隐藏并且会在结尾加上...号,用起 ...

  9. [转载]解决"command 'gcc' failed with exit status 1"错误问题

    转自:https://blog.csdn.net/learn_tech/article/details/80066583 解决"command 'gcc' failed with exit ...

随机推荐

  1. XML与Object的范型转换

    前段时间做object转换xml想了很多,所有打算整理下 做成以下的通用方法. public static bool ObjectToXml<T>(string filePath, T t ...

  2. jmeter3.0生成html格式的dashboard性能测试结果

    jmeter3.0以上支持生成dashboard的html报告,官网介绍:https://jmeter.apache.org/usermanual/generating-dashboard.html ...

  3. 1107 Social Clusters (30 分)(并查集)

    并查集的基本应用 #include<bits/stdc++.h> using namespace std; ; vector<int>vec[N]; int p[N]; con ...

  4. 寻找完全数(C++)

    [问题描述] 输入一个大于 1 的正整数 n,请你将大于 1 和小于或等于 n 的所有完全数输出.所谓完全数就是因子(不算其本身)之和等于它本身的数.例如 1+2+4+7+14=28,所以 28 是完 ...

  5. UnrealEngine4入门(一) 新建一个c++项目

    epic games宣布ue4免费使用(游戏发布之后,每个季度大于3000美元则收取收益的5%)之后,吸引了大批看好VR和AR前景的游戏开发者.不过国内(中文)ue4教程和资料太少,而且一大部分资料都 ...

  6. PostgreSQL 建库建表脚本

    1.创建角色(create_role.sql) drop role if exists "kq_acs";create role "kq_acs" login ...

  7. C#-WinForm控制输入框只接受数字输入

    背景 给导师上一节c#编写数据库应用程序的课,模拟ATM自助取款机的功能写了个winForm程序,关于金额的输入肯定是数字,因此避免输入格式不正确的数字带来异常,直接在输入时进行校验. 封装函数 C# ...

  8. 团队作业4——第一次项目冲刺(Alpha版本)-第一篇

    第一次项目冲刺——第一阶段 今天我们在宿舍开了个会,每个人都斗志昂扬的.撸起袖子加油干! 分工讨论 团队成员 任务 郭达  完成博客随笔和leangoo 刘德培  设计好数据库 石浩洋  搭建好LAM ...

  9. PAT 甲级 1007 Maximum Subsequence Sum

    https://pintia.cn/problem-sets/994805342720868352/problems/994805514284679168 Given a sequence of K  ...

  10. PAT 1065 单身狗

    https://pintia.cn/problem-sets/994805260223102976/problems/994805266942377984 “单身狗”是中文对于单身人士的一种爱称.本题 ...