0

相逢在宇宙 0080

 1 year ago
source link: http://www.sixiaolong.link/2023/02/10/WinUI3%E6%9D%83%E9%99%90%E6%8F%90%E5%8D%87/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

WinUI3权限提升

2023-02-10WinUI

微软总是喜欢先发布一个半成品,WinUI也不例外。早期的WinUI甚至无法做到权限提升,直到现在你去搜索相关内容,排行靠前的依旧是抱怨这一点的issue

不过好在这个问题在WindowsAppSDK v1.1中得到解决,虽然好像没什么人提到这一点。

在WindowsAppSDK支持权限提升后,可以像其他C#项目那样在WinUI中提升权限。具体做法如下:

  1. app.manifest<assemblyIdentity>当中添加:

    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
    <requestedPrivileges>
    <requestedExecutionLevel level="requireAdministrator"/>
    </requestedPrivileges>
    </security>
    </trustInfo>
  2. 以代码形式打开Package.appxmanifest,在<Capabilities>中添加:

    <rescap:Capability Name="allowElevation" />

这样,WinUI项目就可以以管理员身份运行。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK