Set administrator privileges to subprocess.check_call() in Python

后端 未结 2 620
没有蜡笔的小新
没有蜡笔的小新 2020-12-17 08:21

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

2条回答
  •  一向
    一向 (楼主)
    2020-12-17 08:37

    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

提交回复
热议问题