zoukankan      html  css  js  c++  java
  • vs2010添加清单开启UAC以管理员权限运行的功能

    http://blog.csdn.net/sysprogram/article/details/6710092

    http://msdn.microsoft.com/en-us/library/bb756929.aspx

    (1)按照《VS2010与Win7共舞:UAC与数据重定向》上述方法,随便写一个VS2010工程,编译,在这个工程的Debug目录下会有两个文件:   *.exe.embed.manifest 和 *.exe.intermediate.manifest ;

    (2)随便复制一个 .manifest 文件到你现在的工程目录的资源文件夹(res)下,然后在工程的资源中Import这个文件;

    (3)资源文件夹设置为“24”,资源ID设置为“1”;(此步 不知道如何操作...)

    mainfest文件例如:

    <?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="mulitray.exe.manifest" 
      type="win32" 
    /> 
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> 
      <security> 
        <requestedPrivileges> 
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> 
        </requestedPrivileges> 
      </security> 
    </trustInfo> 
    </assembly> 

    貌似要修改下 assemblyIdentity的name为妙.

    我没有设置 什么资源ID,在编译 第一次提示错误,双击错误,转到Debug文件夹下的mainfest, 报错内容是:

    错误    1    error c1010001: Values of attribute "level" not equal in different manifest snippets.    E:\VC2010SP1Samples\C++\MFC\D2D\MFCGdiInteropSample\Debug\MFCGdiInteropSample.exe.intermediate.manifest    1    1    MFCGdiInteropSample

    把对应的requestExecutionLevel 更改,再次编译运行 就可以有管理员权限了.

    话说如何判断当前程序是否在管理员权限运行,找到下面代码,没有验证...

    public static bool IsAdministrator(){
    WindowsIdentity identity=WindowsIdentity.GetCurrent();
    WindowsPrincipal principal=new WindowsPrincipal(identity);
    return principal.IsInRole(WindowsBuiltInRole.Administrator);
    }
  • 相关阅读:
    Cefsharp 75 设置代理
    C# Winform 执行JS脚本
    Cefsharp 75 为每个实例单独设置缓存目录
    QQ邮箱发送邮件,出现mail from address must be same as authorization user错误
    软件卸载后自动重装,服务器中了流氓软件解决方法
    win版宝塔更新后,宝塔无法启动(修复办法)
    C的typedef
    为Arch Linux安装桌面
    在Simplicity Studio下创建适用于EFR32的工程项目
    在VMWare上安装Arch Linux
  • 原文地址:https://www.cnblogs.com/ayanmw/p/2439805.html
Copyright © 2011-2022 走看看