

Writing this question I found more threads on the similar issue, so I adapted the "Update" code in this thread: The batch file to edit Host file is continuosly running without stopping to (only changed the 4th and 5th last written-lines): off Thankfully copied from: Windows batch script - requesting UAC admin rights in a log-friendly way Schtasks.exe /Create /XML "task.xml" /tn "task" ::from this point you can execute your command as admin If exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) If '%errorlevel%' NEQ '0' (GOTO askAdmin)Įcho Requesting administrative privileges.Įcho Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"Įcho UAC.ShellExecute "%~s0", "", "", "runas", 1 > "%temp%\getadmin.vbs"

>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" :: this tests if the file is running as admin The python code calling C:\test\a_task.bat is: import osĪnd the C:\test\a_task.bat contains: OFF When I open the a_task.bat manually it only requests adminstrative privileges once and afterwards successfully adds the task from C:\test\task\task.xml to the windows task scheduler. bat file keeps on opening and closing after I have manually granted permission by clicking the mouse on the approving button, whilst displaying: 'Requesting administrative privileges.". After writing a script in python, that calls C:\test\a_task.bat, the cmd of that.
