.NET MAUI- Windows上的管理特权

发布于 2025-02-11 16:01:23 字数 963 浏览 2 评论 0原文

在Visual Studio Preview中使用.NET MAUI,我无法运行需要管理员特权的Windows应用程序的内容。

我尝试了以下操作:

  • 开放Visual Studio预览为管理员
  • 设置App.Manifest和.csproj,with:

app.manifest

<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <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">
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

.csproj

<ApplicationManifest>app.manifest</ApplicationManifest>

我有一个非常相似的WPF应用程序,如果您在.NET 6中也运行,如果您在.NET 6中运行,如果您在其中工作,如果您可以使用,如果您可以使用。作为管理员运行Visual Studio。

Using .Net MAUI in Visual studio preview i am unable to run things that require administrator privileges for a Windows application.

I have tried the following:

  • Open Visual studio preview as an administrator
  • Setup app.manifest and .csproj with the following:

app.manifest

<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <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">
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

.csproj

<ApplicationManifest>app.manifest</ApplicationManifest>

I have a very similar WPF application, that also runs in .net 6 where admin privileges works if you run Visual studio as an administrator.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞慾 2025-02-18 16:01:23

您在正确的轨道上,但需要另一种成分。用文本编辑器打开package.appxmanifest文件,并确保dablesials节点看起来像这样,

<Capabilities>
    <rescap:Capability Name="runFullTrust" />
    <rescap:Capability Name="allowElevation" />
  </Capabilities>

我添加了允许eLeelevation一个。

然后在您的app.manifestassembly下添加此部分节点,

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>

您可以根据需要调整级别。看来,如果将uiaccess设置为不支持的true。此外,高程仅从Winappsdk 1.1+和:

  • Windows 11- 2022年5月10日至4月10日-KB5013943(OS构建22000.675)

Windows 10- 2022年5月10日至2022年5月10日-KB5013942(OS构建19042.1706,19043.1706,19043.1706,和19044.1706,和19044.1706 href =“ https://learn.microsoft.com/windows/windows/windows-app-sdk/stable-channel#elevation“ rel =” nofollow noreferrer“ Windows-App-SDK/稳定通道#高程

You're on the right track but you need another ingredient. Open the package.appxmanifest file with a text editor and make sure that the Capabilities node looks like this

<Capabilities>
    <rescap:Capability Name="runFullTrust" />
    <rescap:Capability Name="allowElevation" />
  </Capabilities>

I've added the allowElevation one.

Then in your app.manifest add this part right under the assembly node

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>

You can tweak the level as needed. It seems that if you set the uiAccess to true that is not supported. Also, elevation is only available from WinAppSdk 1.1+ and on:

  • Windows 11 - May 10, 2022—KB5013943 (OS Build 22000.675)
  • Windows 10 - May 10, 2022—KB5013942 (OS Builds 19042.1706, 19043.1706, and 19044.1706)

See: https://learn.microsoft.com/windows/apps/windows-app-sdk/stable-channel#elevation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文