页首Html代码

返回顶部

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);
}

 

 

posted @ 2012-04-09 23:53  ayanmw  阅读(10442)  评论(0编辑  收藏  举报

页脚Html代码