Pyinstaller admin权限

.exe.manifest 文件

requireAdministrator 这个是权限的关键

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <assemblyIdentity name="pos_main" processorArchitecture="x86" type="win32" version="1.0.0.0"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>  
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity language="*" name="Microsoft.Windows.Common-Controls" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" type="win32" version="6.0.0.0"/>
      <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"/>
    </dependentAssembly>
  </dependency>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
    </application>
  </compatibility>
</assembly>

命令行方式打包

pyinstaller launcher.py -y -F -w -i updater_64px.ico --uac-admin -r launcher.exe.manifest

如果报文件找不到可保存上面manifest文件, 但是注意文件内OS版本兼容

spec文件方式

打包 pyinstaller xxx.spce

# -*- mode: python -*-

import os
import sys
sys.path.insert(0, os.getcwd())
os.environ["path"] += ";" + os.getcwd()
from kivy_deps import sdl2, glew
from ui.kv import make_ui_cache

_, kv_imports = make_ui_cache(os.getcwd())
print("hiddenimports:{}".format(kv_imports))

block_cipher = None
from version import APP_NAME


a = Analysis(['pos_main.py'],
             pathex=['./'],
             binaries=[],
             datas=[("./drive", "drive"), ("./ui/icon", "ui\\icon"), ("./ui/language/", "ui\\language"),
             ("./ui/kv/cache/", "ui\\kv\\cache"),  # ("./ui/fonts/", "ui\\fonts"),
             ("./pos.ini", "."),
             ("./eftsolutions.properties", "."),
             ],
             hiddenimports= kv_imports + ['six','packaging','packaging.version','packaging.specifiers','configparser'],
             hookspath=[],
             runtime_hooks=[],
             excludes=['cv2'],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name=APP_NAME,
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False,
          icon='ui\\icon\\logo64px.ico',
          version='version.rc',
          uac_admin=True
          )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               upx=True,
               name=APP_NAME)

参考:

pyinstaller打包单文件时--uac-admin选项不起作用怎么办
用Inno setup制作以管理员权限启动的安装包
Windows 应用程序 数字签名(代码签名)流程

posted @ 2020-09-12 11:52  Onsunsl  阅读(657)  评论(0编辑  收藏  举报