Skip to content

Instantly share code, notes, and snippets.

@raincode00
Created December 4, 2014 15:57
Show Gist options
  • Save raincode00/36244ef62d4b13d6ba40 to your computer and use it in GitHub Desktop.
Save raincode00/36244ef62d4b13d6ba40 to your computer and use it in GitHub Desktop.
Embeds manifest file in PyInstaller's windows bootloaders.
"""
Embeds manifest file in PyInstaller's windows bootloaders.
"""
import os
import subprocess
from distutils import msvccompiler
from tempfile import NamedTemporaryFile
def embed_manifest(manifest, target_exe):
msvc = msvccompiler.MSVCCompiler()
msvc.initialize()
mt = msvc.find_exe("mt.exe")
subprocess.call([mt, "-manifest", manifest, "-outputresource:%s;1"%target_exe])
if __name__ == "__main__":
manifest = """<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>"""
working_dir = os.path.dirname(os.path.realpath(__file__))
manifest_file = NamedTemporaryFile(delete=False)
manifest_file.write(manifest)
manifest_file.close()
platforms = [
"Windows-32bit",
"Windows-64bit",
]
exes = [
"run.exe",
"run_d.exe",
"runw.exe",
"runw_d.exe",
]
for p in platforms:
for exe in exes:
exe = os.path.join(working_dir, "bootloader", p, exe)
embed_manifest(manifest_file.name, exe)
os.remove(manifest_file.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment