OultimoCoder
OultimoCoder

Reputation: 294

Using subprocess in Python how do I run 'openvpn' as administrator?

I can run openvpn with default permissions:

FNULL = open(os.devnull, 'w')
args = 'E:\\OpenVPN\\bin\\openvpn-gui.exe --connect ' + server + '.udp.ovpn'
subprocess.Popen(args, stdout=FNULL, stderr=FNULL, shell=False)

How do I change this to ensure it runs as administrator?

Upvotes: 0

Views: 888

Answers (1)

AKX
AKX

Reputation: 168913

You can use the runas utility – untested, the quoting may need some work:

FNULL = open(os.devnull, 'w')
command = 'E:\\OpenVPN\\bin\\openvpn-gui.exe --connect ' + server + '.udp.ovpn'
runas_command = 'runas /user:Administrator "%s"' % command
subprocess.Popen(runas_command, stdout=FNULL, stderr=FNULL, shell=False)

If runas doesn't work, psexec probably will.

Upvotes: 1

Related Questions