Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VBScript

Restarting a windows service using VBScript

5.00/5 (1 vote)
2 Mar 2010CPOL 1  
Set oshell = createobject(Wscript.Shell) oshell.runcmd.exe wscript.sleep 500 oshell.sendkeys net stop Your service name here+({Enter}) wscript.sleep 5000 oshell.sendkeys net start Your service name here+({Enter}) wscript.sleep 5000 ...
MSIL
Set oshell = createobject("Wscript.Shell")
   oshell.run"cmd.exe"
   wscript.sleep 500
   oshell.sendkeys "net stop ""Your service name here"""+("{Enter}")
   wscript.sleep 5000
   oshell.sendkeys "net start ""Your service name here"""+("{Enter}")
   wscript.sleep 5000
   oshell.sendkeys "exit"+("{Enter}")

   set oshell = nothing

   WScript.Quit

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)