I need to run a script that starts a service in python. The problem is that when the command is run in cmd, an UAC window appears. I have found some solutions:
- The easiest one is changing UAC settings so it does not appear. However, I would like to find a way not to have to change my computer settings, since this is dangerous and also we would have to change it in every local computer we might run the script from.
- I found a way to create a task with high administrator rights which means I wouldn't have to change UAC settings, but still the task should be created in all machines.
- I also tried this How to run python script with elevated privilege on windows fix and it works, but the UAC window keeps appearing.
I have even tried clicking on the "Yes" button, but the problem here is that the script stops the moment UAC message appears. I appreciate any ideas on the problem! If I found a way to keep running the script while the message is open, I could easily click "Yes" and that would solve it.
This is the script that I want to run:
import datetime
import win32api, win32con
import sys, os, traceback, types
def run(test, browserName = None):
import win32com.shell.shell as shell
commands = 'python F:\service.py'
shell.ShellExecuteEx(lpVerb='runas', lpFile='cmd.exe', lpParameters='/c '+commands)
and in F:\service.py:
import win32serviceutil
serviceName = "myService"
win32serviceutil.StopService(serviceName)
#From here on is where I try of clicking "Yes" which is not working
x = 953
y = 639
click(x,y)
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)