TA的每日心情 | 奋斗 2015-9-28 15:35 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
3#
楼主 |
发表于 2009-6-4 18:27:29
|
只看该作者
回复 2# 的帖子
是检查本机的服务
直接用下面的函数,没有任何返回值,为什么呐?
Private Function IsServiceRunning(strServiceName)
Dim strComputer, objWMIService, colRunningServices, objService
' Connect to local host
strComputer = "."
objService="Apache2"
' Connect to WMI interface on computer
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
' Select the specified service
Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service where Name='" & strServiceName & "'")
' Read the services state
For Each objService in colRunningServices
Wscript.Echo objService.DisplayName & VbTab & objService.State
Call PrintLn("<strong>" & objService.DisplayName & ": " & objService.State & "</strong>")
If objService.State = "Running" Then
IsServiceRunning = True
Else
IsServiceRunning = False
End If
Next
' Clean up
Set objWMIService = Nothing
Set colRunningServices = Nothing
Set objService = Nothing
End Function |
|