是否可以停止和启动后台服务。
有第三方服务干扰Excel插件。我想在运行代码时暂时将其停止,然后最后将其重新打开。
答案 0 :(得分:0)
只要您想使用Google的“ WMI”功能进行操作,
例如-
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
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