pyinstaller icon indicating copy to clipboard operation
pyinstaller copied to clipboard

Manifest With "requireAdministrator" Doesn't Require Administrator

Open JustAT0rtoise opened this issue 11 months ago • 3 comments

Description of the issue

I am trying to have my GUI program prompt the user for administrative permissions on Windows (UAC), so I have a manifest file to specify that. However, it doesn't prompt UAC in any case I've tried (onedir, onefile, etc).

Context information (for bug reports)

  • Output of pyinstaller --version: 6.17.0
  • Version of Python: 3.13.1
  • Platform: Windows (English)
  • How you installed Python: python.org/downloads
  • Did you also try this on another platform? No

Make sure everything is packaged correctly

  • [x] start with clean installation
  • [x] use the latest development version
  • [x] Run your frozen program from a command window (shell) — instead of double-clicking on it
  • [x] Package your program in --onedir mode
  • [x] Package without UPX, say: use the option --noupx or set upx=False in your .spec-file
  • [x] Repackage you application in verbose/debug mode. For this, pass the option --debug to pyi-makespec or pyinstaller or use EXE(..., debug=1, ...) in your .spec file.

A minimal example program which shows the error

gui.py

print("hello world")

gui.spec

# -*- mode: python ; coding: utf-8 -*-


a = Analysis(
    ['gui.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
    optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.datas,
    [],
    name='gui',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    manifest='gui.exe.manifest',
)

gui.exe.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>

Stacktrace / full error message

There is no formal error message. The program should prompt UAC, but doesn't.

out.txt

JustAT0rtoise avatar Dec 22 '25 11:12 JustAT0rtoise

The execution level privileges settings in final manifest are explicitly controlled by PyInstaller's own switches, --uac-admin and --uac-uiaccess, which end up adding uac_admin=True and uac_uiaccess=True arguments to EXE instantiation in the .spec file.

So if you pass a custom .manifest, <requestedExecutionLevel> ends up being modified w.r.t. PyInstaller's settings. (Consequently, if your only goal is to set execution level privileges, you do not need custom manifest at all).

rokm avatar Dec 22 '25 14:12 rokm

The execution level privileges settings in final manifest are explicitly controlled by PyInstaller's own switches, --uac-admin and --uac-uiaccess, which end up adding uac_admin=True and uac_uiaccess=True arguments to EXE instantiation in the .spec file.

So if you pass a custom .manifest, <requestedExecutionLevel> ends up being modified w.r.t. PyInstaller's settings. (Consequently, if your only goal is to set execution level privileges, you do not need custom manifest at all).

Thank you for this response. I ran PyInstaller with the --uac-admin switch, and now it properly prompts UAC. However, all that using the switch did was add EXE(..., uac_admin=True, ...) to the .spec file. I don't know if this would be the right place to suggest this, but all of these .spec options should definitely be listed in the "Using Spec Files" doc. It would be useful for those who prefer to modify the .spec file directly, rather than having to run PyInstaller with all these switches.

Additionally, in the case that I had a manifest with more content (longPathAware, etc), would those options also get superceded by PyInstaller's manifest? Or, is this only the case with the <requestedExecutionLevel> element?

JustAT0rtoise avatar Dec 22 '25 21:12 JustAT0rtoise

Yeah, I agree that it would be useful to have the arguments for all common .spec targets (Analysis, PYZ, EXE, COLLECT, BUNDLE) listed under "Using Spec Files", similarly to how it is done for Splash target.


We should probably also add a note about what parts of manifest are updated/changed.

If no manifest is provided, the following manifest is used as a base:

https://github.com/pyinstaller/pyinstaller/blob/f60db5e08cb956d5e9fe668fb04cede5373f019d/PyInstaller/utils/win32/winmanifest.py#L27-L57

If manifest is provided, then the provided manifest is used as a base.

And in the manifest (provided or default), we currently change two things:

  • we modify <requestedExecutionLevel> as per uac_admin and auc_uiaccess settings
  • we ensure that the Common-Controls 6.0.0.0 is listed as dependency (that's already the case in the default, but might not be the case in user-supplied manifest)

The rest of manifest should remain unchanged. (And since you mention longPathAware, you can see that this one is included in our default manifest).

https://github.com/pyinstaller/pyinstaller/blob/f60db5e08cb956d5e9fe668fb04cede5373f019d/PyInstaller/utils/win32/winmanifest.py#L157-L194

rokm avatar Dec 22 '25 21:12 rokm