vendredi 15 novembre 2019

Run cmd command using python (Stop/Start a service)

So, i would like to know if someone knows how to stop/start service using python, IIS (W3SVC - service name), i tried to do it several times, unfortunately nothing worked (tried it with subprocess, create function with os to launch cmd, tried to connect as an admin ...). So here is the closest one that i could get :

# stop the service
args = ['sc', 'stop', 'W3SVC']
subprocess.run(args)
# start the service
args[1] = 'start'
subprocess.run(args)

But it returns access denied :

[SC] OpenService échec(s) 5

[SC] StartService: OpenService échec(s) 5

It is in French, échec(s) means failure.

I am using it to automatize a test with selenium, I would really appreciate some help.

Aucun commentaire:

Enregistrer un commentaire