本帖最后由 czjt1234 于 2015-5-5 22:49 编辑
- Dim Shell, fso, TextStream, s
-
- s = "Helpsvc" '服务名
- Set Shell = CreateObject("Shell.Application")
- Set fso = CreateObject("Scripting.FileSystemObject")
-
- If Shell.CanStartStopService(s) = False Then
- MsgBox "当前用户没有权限启动和停止指定的服务", 4096
- WScript.Quit()
- End If
-
- Do
- If Shell.IsServiceRunning(s) = False Then
- Set TextStream = fso.OpenTextFile("日志.txt", 8, True)
- If Shell.ServiceStart(s, False) = False Then
- TextStream.WriteLine Now() & " 启动服务失败"
- Else
- TextStream.WriteLine Now() & " 启动服务成功"
- End If
- TextStream.Close()
- End If
- WScript.Sleep 1000 * 60 '1分钟
- Loop
复制代码
简化版
- s = "Helpsvc" '服务名
- Set Shell = CreateObject("Shell.Application")
- Do
- If Shell.IsServiceRunning(s) = False Then
- Shell.ServiceStart s, False
- End If
- WScript.Sleep 1000 * 60 '1分钟
- Loop
复制代码
|