如何使用 vbscript 检查服务状态? [英] how to check service state using vbscript?

查看:51
本文介绍了如何使用 vbscript 检查服务状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何可以使用 vbscript 检查服务状态吗?我想为每个可能的服务状态提供一个功能:LINK任何帮助都会很棒.我确实写了一个函数来检查服务是否停止:

Is there anyway to check the status of service using vbscript ? I would like to have a function for each possible service state : LINK Any help would be great. I did write a function for checking if service is stopped :

Public Function IsServiceStop(ByVal serviceName)
    On Error Resume Next
    Dim objServices, service
    Set oWmiService = GetObject("winmgmts:\\.\root\cimv2")
    Set objServices = oWmiService.ExecQuery("Select * from Win32_Service where Name='" & serviceName & "'")
    For Each service In objServices
        IsServiceStop = (service.Started = False)
        Exit Function
    Next
    IsServiceStop = True
    On Error Goto 0
End Function

推荐答案

如有疑问,请阅读 文档.您需要做的就是检查服务对象的 State 属性:

When in doubt, read the documentation. All you need to do is check the State property of the service object:

serviceName = "..."

Set wmi = GetObject("winmgmts://./root/cimv2")
state = wmi.Get("Win32_Service.Name='" & serviceName & "'").State
WScript.Echo state

这篇关于如何使用 vbscript 检查服务状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆