惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
C
Check Point Blog
雷峰网
雷峰网
小众软件
小众软件
GbyAI
GbyAI
美团技术团队
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
WordPress大学
WordPress大学
MyScale Blog
MyScale Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
Jina AI
Jina AI
爱范儿
爱范儿
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美

博客园 - 极无宪

小红书如何采集市集 Textrimming 失效怎么办? 现在找个vs2019 安装好难呀! WPF:如何将调试信息写入到输出窗口? System.Net.WebException: 远程服务器返回错误: (405) 不允许的方法。 警惕:开启了 SQL Profiler监测SQL语句忘记关了,C盘居然被占满了 nuget 总是获取失败怎么办? 还在用WebBrowser吗?你out了! 关于打印机共享的注意事项——又被叫去修电脑了 MVVM转换器Int2StringConverter基础类 ServicesController 的使用 winform中坐标系转换的问题,获取某点在屏幕中的绝对位置等 使用本地IIS Web 服务起转到win7 iis7后的系列问题 客户端元素中找不到与此名称匹配的终结点 关于错误的友好提示 调侃 亚马逊的 kindlegen propertygrid 下拉列表 vs 已经在解决方案中打开了具有该名称的项目 解决方案"System.InvalidOperationException: 配置有 NoSecurityChanges 标志的 AppDomainManager 修改了 AppDomain 的安全状态"
VC编写在windows7下以管理员权限运行的程序(转)
极无宪 · 2013-01-24 · via 博客园 - 极无宪

2013-01-24 10:48  极无宪  阅读(601)  评论()    收藏  举报

方法一: VC6:导入manifest文件

1.新建一文件命名为 xxx.manifest.内容如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><assemblyIdentity
    version="1.0.0.0"
    processorArchitecture="X86"
    name="test.exe.manifest"
    type="win32"/><trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"><security><requestedPrivileges><requestedExecutionLevel level="requireAdministrator" uiAccess="false"/></requestedPrivileges></security></trustInfo></assembly>

 注:此文件只要扩展名是.manifest文件名可以任意。文件内容的name属性值也可以为任意。(VC6.0下经过测试)

2.把此文件"import"到资源文件中,资源类型为24,资源ID为1,

注:经测试资源类型必须为24,资源ID也必须为1,

3.重新编辑即可,在windows7下该程序图标有一个盾状小图标,双击运行会出现对话框要求提升为管理员权限。

 (

我试验了下vs2003,

1.先建一个manifest文件,name="Microsoft.Windows.[应用程序名]"

2.将该文件复制到工程文件夹中的rec文件夹中。
3.工程->添加资源->rec文件夹中的[应用程序名].manifest文件添加到工程中。
4.打开resource.h文件,将下面两行代码复制并粘贴
#define IDR_MANIFEST                    1
#define RT_MANIFEST                     24

5.打开工程中的.rc文件,将下面一行代码加入到该文件中
IDR_MANIFEST RT_MANIFEST MOVEABLE PURE "res\\[应用程序名].manifest"
6.重新编译链接,OK成功。

)

如果是VC 2008或者2010  就更简单了,直接项目右键---属性---连接器---清单文件---uac执行级别  选择requireAdministrator  重新编译  这样你的程序直接运行就拥有管理员权限了。

如果是C#.NET 2008或2010,则直接在项目中添加一个manifest文件,如app.manifest,创建后,把<requestedExecutionLevel  level="asInvoker" uiAccess="false" />中的asInvoker替换成requireAdministrator即可,如:

<?xml version="1.0" encoding="utf-8"?><asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><assemblyIdentity version="1.0.0.0" name="MyApplication.app"/><trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"><security><requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"><!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        --><requestedExecutionLevel level="requireAdministrator" uiAccess="false"/></requestedPrivileges></security></trustInfo></asmv1:assembly>

方法二:修改注册表:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\\Program Files\\win7test2.exe"="RUNASADMIN"

将上面的内容保存为.reg文件,基中把C:\\Program Files\\win7test2.exe改为真实环境的应用程序地址,双击运行即可。

    这种方法后应用程序图标不会有盾状图标,但双击运行仍然会弹出对话框要求提升权限。

附:XP风格的manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><dependency><dependentAssembly><assemblyIdentity  
  type="win32"  
  name="Microsoft.Windows.Common-Controls"  
  version="6.0.0.0"  
  processorArchitecture="X86"  
  publicKeyToken="6595b64144ccf1df"  
  language="*"/></dependentAssembly></dependency></assembly>