I want to run a batch file which changes my ip address by static
// sth.bat
netsh int ip set address "Wifi" static xxxx.xxxx.xxxx.xxxx 255.255.255.0 xxxx.xxxx.xxxx.x 1
changing the ip address requires administrator rights so i want to use the subprocess module to run the file as admin
by the following python module
// ip_changer.py
import subprocess,time,socket
from subprocess import PIPE,STDOUT
p = subprocess.Popen("runas /user:Administrator "C:/Users/userName/sth.bat"", shell = True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
print(p.communicate(input = bytes("myPassword","utf-8")))
the communicate tuple returns me the following:
(b'Geben Sie das Kennwort fx81r "Administrator" ein: x00
', None)
where the first entry is the question for the password from the shell, but my ip doesn't change at all.
Running the .bat file manually works fine.
Do i send the pasword before it is requested?
Or do you see what's wrong there ?
would be great to get some help here.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…