I call two executables from a python script one which needs Administrator privileges and one which does not need them. Is there any way by which I can set the Administrator
I found a nasty workaround
f = open('test.cmd', 'w+')
f.write("execute.exe")
f.close()
os.system("runas /savecred /profile /user:Administrator \"test.cmd\"")
or you can use subprocess
Try this out for entering an administrative password.
import subprocess as sp
sp.check_call(['DoesnotNeedAdminPrivilege.exe'])
prog = sp.Popen(['runas', '/noprofile', '/user:Administrator', 'NeedsAdminPrivilege.exe'],stdin=sp.PIPE)
prog.stdin.write('password')
prog.communicate()
Here are the docs on:
Popen - http://docs.python.org/2/library/subprocess.html#popen-constructor
runas - http://technet.microsoft.com/en-us/library/cc771525.aspx
if this works will depend on the program NeedsAdminPrivilege.