代码之家  ›  专栏  ›  技术社区  ›  Dror Helper

以管理员身份运行.NET应用程序

  •  5
  • Dror Helper  · 技术社区  · 15 年前

    我注意到一些应用程序(如防病毒、控制面板)有一个小屏蔽,当我运行这些应用程序时,windows会自动向我请求管理员权限。

    有没有办法告诉windows(以编程方式)我希望应用程序以管理权限运行?

    4 回复  |  直到 15 年前
        1
  •  7
  •   Gene Goykhman    15 年前

    您需要在应用程序清单中将应用程序标记为需要管理员权限。 Here's an article from MSDN Magazine

        2
  •  16
  •   dso    15 年前

    创建应用程序清单,将requestedExecutionLevel设置为RequiredMinstrator:

    示例(添加应用程序清单时由VS生成):

    <?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>
    

    如果将其添加到Visual Studio应用程序项目中,则在编译时它将嵌入到程序集中。

        3
  •  1
  •   Konamiman    15 年前

    您应该向应用程序添加应用程序清单,并将其配置为请求管理员权限。请看这里: http://www.professionalvisualstudio.com/blog/2007/10/05/enabling-your-application-for-uac-on-vista/

        4
  •  1
  •   Community T.Woody    7 年前

    另一种在应用程序启动时提升用户权限的解决方案如下所述: Pimp my UAC and a few questions about it