1

I want to open a ".exe" extention file in windows OS 8.1 . It requires User Account Control to open the file. Is it possible to always allow python script to open exe file without UAC.

In pywinauto, i am getting the following error:--

  File "C:\Python27\lib\site-packages\pywinauto\application.py", line 997, in start
    raise AppStartError(message)
pywinauto.application.AppStartError: Could not create the process "testfile.exe"
Error returned by CreateProcess: (740, 'CreateProcess', 'The requested operation requires elevation.')
nikhilesh_koshti
  • 393
  • 1
  • 10

1 Answers1

1

Disabling UAC manually in OS settings is the only way. Or run script as Administrator with manual confirmation. The UAC confirmation dialog is not automatable for security reasons. I’ve tested this.

Maybe Task Scheduler trigger can be set to run as Administrator with the only confirmation on trigger save.

[EDIT]: If UAC is disabled manually, there is a way to re-run the script as Administrator:

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • Thanks for update. But even after disabling UAC in OS settings, UAC has been bypassed when I click on exe file. But still error occured in pywinauto. `from pywinauto.application import Application Application().Start("testfile.exe")` Is there any way to handle it in python? – nikhilesh_koshti Jul 29 '18 at 05:55
  • It can be forced to “run as Administrator” mode using function ShellExecuteEx. This is not implemented in pywinauto, so I can provide code sample when I get back to my PC. – Vasily Ryabov Jul 29 '18 at 15:27
  • Well, I've edited my post with the link to another answer with code sample. – Vasily Ryabov Jul 30 '18 at 19:22
  • 2
    Thanks for the update. I also found one more way to bypass UAC in python script to set the COMPAT_LAYER variable to RUnAsInvoker `os.environ.update({"__COMPAT_LAYER":"RUnAsInvoker"}) ` – nikhilesh_koshti Aug 04 '18 at 06:52