electron应用以管理员权限启动

Posted ypengbk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了electron应用以管理员权限启动相关的知识,希望对你有一定的参考价值。

最近在用electron开发PC桌面应用,其中有个需求就是整个应用以管理员权限启动。很头痛,各种google,baidu。

最后终于解决了,可以分为三个步骤,做个总结分享。

  一、如果没有manifest.xml文件的话

可通过执行命令:mt.exe -inputresource:某某.exe -out:extracted.manifest导出 manifest.xml;

  二、如果有的manifest.xml文件的话,按照标红处修改;

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<dependency>
<dependentAssembly>
<assemblyIdentity type="Win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0"
processorArchitecture="*" publicKeyToken="6595b64144ccf1df"
language="*"></assemblyIdentity>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<!-- 修改前 -->
<!--
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
-->
<!-- 修改后 -->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
<!-- end 修改 -->
</requestedPrivileges>
</security>
</trustInfo>
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true/pm</dpiAware>
<disableWindowFiltering xmlns="http://schemas.microsoft.com/SMI/2011/WindowsSettings">true
</disableWindowFiltering>
</asmv3:windowsSettings>
</asmv3:application>
<ms_compatibility:compatibility xmlns:ms_compatibility="urn:schemas-microsoft-com:compatibility.v1"
xmlns="urn:schemas-microsoft-com:compatibility.v1">
<ms_compatibility:application xmlns:ms_compatibility="urn:schemas-microsoft-com:compatibility.v1">
<ms_compatibility:supportedOS xmlns:ms_compatibility="urn:schemas-microsoft-com:compatibility.v1"
Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"></ms_compatibility:supportedOS>
<ms_compatibility:supportedOS xmlns:ms_compatibility="urn:schemas-microsoft-com:compatibility.v1"
Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"></ms_compatibility:supportedOS>
<ms_compatibility:supportedOS xmlns:ms_compatibility="urn:schemas-microsoft-com:compatibility.v1"
Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></ms_compatibility:supportedOS>
<ms_compatibility:supportedOS xmlns:ms_compatibility="urn:schemas-microsoft-com:compatibility.v1"
Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"></ms_compatibility:supportedOS>
<ms_compatibility:supportedOS xmlns:ms_compatibility="urn:schemas-microsoft-com:compatibility.v1"
Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></ms_compatibility:supportedOS>
</ms_compatibility:application>
</ms_compatibility:compatibility>
</assembly>

  三、最后执行命令:mt.exe -manifest manifest.xml -outputresource:你的应用名字.exe



以上是关于electron应用以管理员权限启动的主要内容,如果未能解决你的问题,请参考以下文章

可以将Visual Studio代码配置为启动电子

仅创建 Google Marketplace 应用以授予对 service_account (GSuite) 的 API 访问权限

如何修复“代码应明确检查权限是不是可用”错误

如何强制 iOS 应用以纵向模式启动

Electron常见问题 61 - 客户端必须以管理员权限运行?

Electron常见问题 61 - 客户端必须以管理员权限运行?