Misconfigured path causes PermissionError within subprocess.Popen call
See original GitHub issuepython runned from cmd with admin privileges.
running any action, e.g. ahk.mouse_move(x=100, y=100, speed=30, blocking=False)
will throw PermissionError:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python\Python37\lib\site-packages\ahk\mouse.py", line 89, in mouse_move
self.run_script(script, blocking=blocking)
File "C:\Python\Python37\lib\site-packages\ahk\script.py", line 76, in run_script
result = self._run_script(script_text, decode=decode, blocking=blocking, **runkwargs)
File "C:\Python\Python37\lib\site-packages\ahk\script.py", line 66, in _run_script
proc = subprocess.Popen(runargs, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
File "C:\Python\Python37\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Python\Python37\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
Checking permissions from PowerShell:
PS D:\Prog\AutoHotkey> Get-Acl | fl
Path : Microsoft.PowerShell.Core\FileSystem::D:\Prog\AutoHotkey
Owner : BUILTIN\Administrators
Group : G:S-1-5-21-1413140394-118887914-2539411025-513
Access : Все Allow FullControl
NT AUTHORITY\SYSTEM Allow FullControl
S-1-5-21-1413140394-118887914-2539411025-1000 Allow FullControl
BUILTIN\Administrators Allow FullControl
Audit :
Sddl : O:BAG:S-1-5-21-1413140394-118887914-2539411025-513D:AI(A;OICIID;FA;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;S-1-5
-21-1413140394-118887914-2539411025-1000)(A;OICIID;FA;;;BA)
PS D:\Prog\AutoHotkey> Dir | Get-Acl | fl
...
Path : Microsoft.PowerShell.Core\FileSystem::D:\Prog\AutoHotkey\AutoHotkey.exe
Owner : BUILTIN\Administrators
Group : G:S-1-5-21-1413140394-118887914-2539411025-513
Access : Все Allow FullControl
NT AUTHORITY\SYSTEM Allow FullControl
S-1-5-21-1413140394-118887914-2539411025-1000 Allow FullControl
BUILTIN\Administrators Allow FullControl
Audit :
Sddl : O:BAG:S-1-5-21-1413140394-118887914-2539411025-513D:AI(A;ID;FA;;;WD)(A;ID;FA;;;SY)(A;ID;FA;;;S-1-5-21-14131403
94-118887914-2539411025-1000)(A;ID;FA;;;BA)
Path : Microsoft.PowerShell.Core\FileSystem::D:\Prog\AutoHotkey\AutoHotkeyA32.exe
Owner : BUILTIN\Administrators
Group : G:S-1-5-21-1413140394-118887914-2539411025-513
Access : Все Allow FullControl
NT AUTHORITY\SYSTEM Allow FullControl
S-1-5-21-1413140394-118887914-2539411025-1000 Allow FullControl
BUILTIN\Administrators Allow FullControl
Audit :
Sddl : O:BAG:S-1-5-21-1413140394-118887914-2539411025-513D:AI(A;ID;FA;;;WD)(A;ID;FA;;;SY)(A;ID;FA;;;S-1-5-21-14131403
94-118887914-2539411025-1000)(A;ID;FA;;;BA)
Path : Microsoft.PowerShell.Core\FileSystem::D:\Prog\AutoHotkey\AutoHotkeyU32.exe
Owner : BUILTIN\Administrators
Group : G:S-1-5-21-1413140394-118887914-2539411025-513
Access : Все Allow FullControl
NT AUTHORITY\SYSTEM Allow FullControl
S-1-5-21-1413140394-118887914-2539411025-1000 Allow FullControl
BUILTIN\Administrators Allow FullControl
Audit :
Sddl : O:BAG:S-1-5-21-1413140394-118887914-2539411025-513D:AI(A;ID;FA;;;WD)(A;ID;FA;;;SY)(A;ID;FA;;;S-1-5-21-14131403
94-118887914-2539411025-1000)(A;ID;FA;;;BA)
Path : Microsoft.PowerShell.Core\FileSystem::D:\Prog\AutoHotkey\AutoHotkeyU64.exe
Owner : BUILTIN\Administrators
Group : G:S-1-5-21-1413140394-118887914-2539411025-513
Access : Все Allow FullControl
NT AUTHORITY\SYSTEM Allow FullControl
S-1-5-21-1413140394-118887914-2539411025-1000 Allow FullControl
BUILTIN\Administrators Allow FullControl
Audit :
Sddl : O:BAG:S-1-5-21-1413140394-118887914-2539411025-513D:AI(A;ID;FA;;;WD)(A;ID;FA;;;SY)(A;ID;FA;;;S-1-5-21-14131403
94-118887914-2539411025-1000)(A;ID;FA;;;BA)
...
It’s looks like need to run subprocess from admin privileges as well. For this need to add to subprosess.Popen these args before running AutoHotkey.exe executable:
'runas', '/noprofile', '/user:Administrator',
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
python subprocess Popen environment PATH? - Stack Overflow
Typing echo $PATH inside the shell that this opens reveals that the PATH value is not empty, and also different from the value...
Read more >Changelog — Python 3.11.1 documentation
gh-99729: Fix an issue that could cause frames to be visible to Python code as they are being torn down, possibly leading to...
Read more >Permission Error with subprocess.Popen() : r/learnpython
Popen (), but always got the error, and at the same time I was able to launch the same programs with os.system('open AppName')....
Read more >The subprocess Module: Wrapping Programs With Python
In this tutorial, you'll learn how to leverage other apps and programs that aren't Python, wrapping them or launching them from your Python...
Read more >Python Tutorial: subprocesses module - 2020 - BogoToBogo
We cannot use UNIX commands in our Python script as if they were Python code. ... PIPE in the Popen call, we'll just...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, I delete
AHK_PATH
variable and now everything is works without extra definition to path.Marking this one as resolved and using #32 to track progress on action items for changes.
Feel free to reopen or pick up in 32 if you have more questions on this.
Thanks again for the report!