When I start
os.system('"runas /user:USERNAME "C:/Python27/python.exe shell.py""')
it iterates over and over in Console.
I need to start a program from computer owner to elevate the rights, since program will be used on Win7, which leads to care about UAC.
I decided to go in a way that to start the program inside, but with elevated rights and exit immediately.
I used this code
import os
import sys
import win32com.shell.shell as shell
ASADMIN = 'asadmin'
if sys.argv[-1] != ASADMIN:
script = os.path.abspath(sys.argv[0])
params = ' '.join([script] + sys.argv[1:] + [ASADMIN])
shell.ShellExecuteEx(lpVerb='runas', lpFile=sys.executable, lpParameters=params)
` But in my case nothig starts with ShellExecuteEx. And instead of ShellExecuteEx I put os.system using runas command, which iterated in Console string like runas /user:USERNAME "C:/Python27/python.exe shell.py" over and over.
import os
import sys
import win32com.shell.shell as sh ASADMIN = '/user:@'
os.system('"runas /user:=@COMPANY_NAME "C:/Python27/python.exe shell.py""')
sys.exit(0)
if sys.argv[-1] != ASADMIN:
script = os.path.abspath(sys.argv[0])
params = ' '.join([ASADMIN] + ['c:\\Python27\\python.exe', script] + sys.argv[1:])
sh.ShellExecuteEx(lpVerb='runas', lpFile=sys.executable, lpParameters=params)
sys.exit(0)
This is my code.