qtp check windows service state
QTP 怎样实现获得某个服务是否存在,并检查当前状态eg:check apache service if exist and check its states 检查本机的还是远端主机的?
本地主机的wmi可以,获取running service列表,然后看看服务在不在
如果是验证远端的主机当然如果有权限的也可以wmi,登录进去,验证下
如果没有登录权限就要麻烦点了,要验证服务所在端口是否正确开放等等,具体要看你的需求了
回复 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 Function IsServiceRunning(strServiceName)
IsServiceRunning = False
Set wmi=GetObject("winmgmts:\\.")
Set pro_s=wmi.instancesof("win32_Service")
For Each p In pro_s
If p.name=strServiceName andp.started = True Then
IsServiceRunning = True
End If
Next
Set pro_s=Nothing
Set wmi=Nothing
End Function
msgboxIsServiceRunning("W32Time")
写了个短点的,请试试,我在WinXP SP3 + QTP 9.5上试过可以了 收藏,学习
回复 4# 的帖子
多谢!已经试过了,可以通过。:handshake 学习 看到了wmi的应用了,:lol 收藏 学习了 高手啊
页:
[1]