0

Is it possible to stop and start a background service.

There is a third party service that is interfering with an Excel Plug-In. I want to temporarily stop it when I run my code, and then turn it back on at the end.

  • Hmmm, if it would be possible, which I assume it might (not really convinced); does excell has sufficient rights to stop the service? – Stefan Mar 01 '19 at 10:46
  • Maybe you can start cmd.exe and start/stop the service; https://stackoverflow.com/q/17956651/3927703 – Alex de Jong Mar 01 '19 at 10:55

1 Answers1

0

Whenever you want to do something like this a Google using "WMI" will probably get you something useful.

For example -

From: https://learn.microsoft.com/en-us/windows/desktop/cimwin32prov/stopservice-method-in-class-win32-service

Set ServiceSet = GetObject("winmgmts:").ExecQuery( _
          "select * from Win32_Service where Name='ClipSrv'")

for each Service in ServiceSet
 RetVal = Service.StopService()
 if RetVal = 0 then 
  WScript.Echo "Service stopped" 
 elseif RetVal = 5 then 
  WScript.Echo "Service already stopped" 
 end if
next

Similarly: https://learn.microsoft.com/en-us/windows/desktop/cimwin32prov/startservice-method-in-class-win32-service

Set ServiceSet = GetObject("winmgmts:").ExecQuery( _
           "select * from Win32_Service where Name='ClipSrv'")

for each Service in ServiceSet
 RetVal = Service.StartService()
 if RetVal = 0 then WScript.Echo "Service started"
 if RetVal = 10 then WScript.Echo "Service already running"
next
Tim Williams
  • 154,628
  • 8
  • 97
  • 125