pyinstaller icon indicating copy to clipboard operation
pyinstaller copied to clipboard

UAC not working in onefile again, migrate old UAC test

Open moden-py opened this issue 10 years ago • 35 comments

I am not able to create one file executable with UAC. Here is the project I am trying to add the UAC window - https://github.com/pywinauto/SWAPY python27 latest-pyinstaller\pyinstaller.py --uac-admin -F swapy-ob.py Single exe file does not ask for Admin rights.

With -D works fine, since the manifest placed near the exe.

I've tried Python 2.7.x 32/64bit, PyInstaller from the master/develop/pip - it did not help. Test pyinstaller\tests\old_suite\interactive\test_onefile_win32_uac_admin.py passed but produced an exe file without UAC request.

# -*- mode: python -*-

block_cipher = None


a = Analysis(['swapy-ob.py'],
             pathex=['PATH\\swapy'],
             binaries=None,
             datas=None,
             hiddenimports=[],
             hookspath=None,
             runtime_hooks=None,
             excludes=None,
             win_no_prefer_redirects=None,
             win_private_assemblies=None,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='swapy-ob',
          debug=False,
          strip=None,
          upx=True,
          console=True , uac_admin=True)

PS: I've read previous related issues, #853, etc.

moden-py avatar Dec 16 '15 22:12 moden-py

Does UAC work with just simple helloworld app?

matysek avatar Dec 17 '15 18:12 matysek

@codewarrior0 Do you have an idea how could we test the old test test_onefile_win32_uac_admin.py in appveyor?

matysek avatar Dec 17 '15 18:12 matysek

Just test it as other interactive tests - check if it keeps running for a period of time - supposing that it's waiting for the user to permit admin access?

matysek avatar Dec 17 '15 18:12 matysek

Does not work with simple helloworld. I noticed a strange behavior, if I take the manifest file from helloworld\build\helloworld\ and place it near the onefile exe - UAC does not work(both has the same name, I expect it would). But if rename the exe and the manifest from the original name to a some the same name - UAC works properly. For instance to helloworld1.exe and helloworld1.exe.manifest. Rename back to the original name - does not work. It is strange. It looks like the exe has broken embedded manifest, and it start work only if I rename from the original name and place a new manifest. But ResHaker shows no embedded manifest in the onefile exe.

helloworld.zip

PATH\pyinstaller>pyinstaller.py -F --uac-admin helloworld.py
174 INFO: PyInstaller: 3.0
175 INFO: Python: 2.7.10
176 INFO: Platform: Windows-7-6.1.7601-SP1

moden-py avatar Dec 17 '15 19:12 moden-py

And the latest develop works for you?

matysek avatar Dec 17 '15 19:12 matysek

@matysek, I have one idea how to deal with UAC in the tests. I've just checked when UAC window is open I cannot catch it ;-) but I still can deal with UAC's accompanying windows. On my Win7 when UAC starts i see two new windows with classes:

  1. TaskSwitcherWnd - also happens when you switch by Ctrl-Alt.
  2. IME (text - Default IME) - Input Method Editor, the language change window.

I can check the behavior on appveyor CI tomorrow.

import time
import pywinauto

app = pywinauto.application.Application()

old_windows = set(pywinauto.findwindows.find_windows(top_level_only=False, visible_only=False))

while True:
    new_windows = set(pywinauto.findwindows.find_windows(top_level_only=False, visible_only=False))
    difference = new_windows.difference(old_windows)
    if difference:
        print 'New windows'
        for nwh in difference:
            nw = app.window_(handle=nwh)
            print nw.Texts()
            print nw.Class()
            time.sleep(1)
    else:
        pass
    old_windows = new_windows
    time.sleep(0.1)

moden-py avatar Dec 17 '15 19:12 moden-py

@matysek

And the latest develop works for you? Unfortunately no. Have just update to SHA-1: 93d25e563e49f88f5977afd9b6e26cb34bfb5efa

moden-py avatar Dec 17 '15 19:12 moden-py

Do you have an idea how could we test the old test test_onefile_win32_uac_admin.py in appveyor?

I'll take a look at reviving this test.

I've got a hunch about what's happening here. It's a catch-22.

UAC options in the manifest only take effect if it is automatically loaded by Windows. The manifest automatically loaded by Windows cannot specify the MSVCRT libs because the onefile app needs to extract them to a tempdir. The MSVCRT libs must be specified in the manifest marked as "process default". Any manifest automatically loaded by Windows becomes the "process default". Thus, the onefile app does not include a manifest that will be automatically loaded, and instead explicitly loads it with the WinAPI while passing a flag that marks it as the "process default" manifest.

codewarrior0 avatar Dec 18 '15 02:12 codewarrior0

Here is a very simple reproduction of the same symptom (i.e. UAC does not work with onefile):

pyi-makespec --onefile helloworld.py
pyinstaller --uac-admin helloworld.spec

Any helloworld.py will do. A useful one in this case might be:

import ctypes
print ctypes.windll.shell32.IsUserAnAdmin()

I'm using pyinstaller version 3.1. What's going on? There doesn't seem to be any manifest embedded in helloworld.exe at all.

Any help appreciated.

berwynhoyt avatar Jan 13 '16 04:01 berwynhoyt

Any update on this issue?

dnides avatar Apr 13 '16 15:04 dnides

Also have the issue with onefile option. I can check the compiled exe with Sigcheck -m and it shows no manifest. It still works in folder mode. I also tried using the --manifest but it seems to be simply ignored.

themaxx75 avatar Apr 13 '16 18:04 themaxx75

Same issue here, the uac_admin=True works fine when used with the COLLECT, but permission is not asked when in onefile mode.

pipoupiwam avatar Apr 26 '16 12:04 pipoupiwam

I found a workaround although I don't know exactly why it worked :smile:

If you use pyinstaller --onefile --uac-admin my_app.py It will create a .spec file without COLLECT right? So I will add this below that .spec file, build again with that .spec file and I get a my_app folder with an exe file and a manifest file :smiley:

coll = COLLECT(exe,
               strip=False,
               upx=True,
               name='my_app'
)

p/s: Don't forget uac_admin=True in exe = EXE .... :smile:

Test on: Windows 8.1 64bit, python 2.7.11 64 bit, pyinstaller 3.1.1

pc223 avatar May 02 '16 02:05 pc223

The current solution is using develop version of pyinstaller. Works fine for me.

ghost avatar Jun 15 '16 09:06 ghost

I've just tried the develop version (3.3.dev0+d25657e), but to no avail. No admin rights are asked when producing a onefile executable.

siwyd avatar Jun 15 '16 12:06 siwyd

Strange, I'm fine with it. This is my spec file:

block_cipher = None
a = Analysis(['connector_source.py'],
             pathex=['*path*'],
             binaries=None,
             datas=None,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='connector',
          debug=False,
          strip=False,
          upx=True,
          console=False , uac_admin=True, icon='icon.ico')
coll = COLLECT(exe,
               strip=False,
               upx=True,
               name='connector)

ghost avatar Jun 15 '16 12:06 ghost

Seems very similar to mine:

block_cipher = None

a = Analysis(['bednetstick.py'],
             pathex=['E:\bednetstick'],
             binaries=[],
             datas=[('data','.')],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='bednetstick',
          debug=False,
          strip=False,
          upx=True,
          console=False , uac_admin=True)

siwyd avatar Jun 15 '16 12:06 siwyd

I have the same issue with python 3.5 (x64) and latest windows. Is there a working fix?

lanzorg avatar Aug 28 '16 14:08 lanzorg

I tried with almost any recent python2 and python3 releases on my win10 and nothing works! Are you working on a fix?

lanzorg avatar Sep 06 '16 21:09 lanzorg

I have the same issue on python 2.7 pyinstaller 3.1.1 on windows 7

sfantu avatar Sep 12 '16 00:09 sfantu