'项目中用到的代码,分享出来 by redice
'判断服务是否安装
Public Function isInstalled(service As String) As Boolean
On Error Resume Next
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
If colProcessList.Count > 0 Then
isInstalled = True
Else
isInstalled = False
End If
Set objWMIService = Nothing
Set objProcess = Nothing
End Function
'判断服务是否停止
Public Function isStopped(service As String) As Boolean
On Error Resume Next
isStopped = False
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
For Each objProcess In colProcessList
If LCase(objProcess.State) = "stopped" Then
isStopped = True
Set objWMIService = Nothing
Set objProcess = Nothing
Exit Function
End If
Next
Set objWMIService = Nothing
Set objProcess = Nothing
End Function
'停止服务
Public Sub stopService(service As String)
On Error Resume Next
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
For Each objProcess In colProcessList
objProcess.stopService
Next
Set objWMIService = Nothing
Set objProcess = Nothing
End Sub
启动服务
Public Sub startService(service As String)
On Error Resume Next
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
For Each objProcess In colProcessList
objProcess.startService
Next
Set objWMIService = Nothing
Set objProcess = Nothing
End Sub
'禁用服务
Public Sub disableService(service As String)
On Error Resume Next
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
For Each objProcess In colProcessList
objProcess.ChangeStartMode ("Disabled")
Next
Set objWMIService = Nothing
Set objProcess = Nothing
End Sub
'启用服务
Public Sub enableService(service As String)
On Error Resume Next
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
For Each objProcess In colProcessList
objProcess.ChangeStartMode ("Automatic")
Next
Set objWMIService = Nothing
Set objProcess = Nothing
End Sub
'判断服务是否安装
Public Function isInstalled(service As String) As Boolean
On Error Resume Next
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
If colProcessList.Count > 0 Then
isInstalled = True
Else
isInstalled = False
End If
Set objWMIService = Nothing
Set objProcess = Nothing
End Function
'判断服务是否停止
Public Function isStopped(service As String) As Boolean
On Error Resume Next
isStopped = False
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
For Each objProcess In colProcessList
If LCase(objProcess.State) = "stopped" Then
isStopped = True
Set objWMIService = Nothing
Set objProcess = Nothing
Exit Function
End If
Next
Set objWMIService = Nothing
Set objProcess = Nothing
End Function
'停止服务
Public Sub stopService(service As String)
On Error Resume Next
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
For Each objProcess In colProcessList
objProcess.stopService
Next
Set objWMIService = Nothing
Set objProcess = Nothing
End Sub
启动服务
Public Sub startService(service As String)
On Error Resume Next
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
For Each objProcess In colProcessList
objProcess.startService
Next
Set objWMIService = Nothing
Set objProcess = Nothing
End Sub
'禁用服务
Public Sub disableService(service As String)
On Error Resume Next
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
For Each objProcess In colProcessList
objProcess.ChangeStartMode ("Disabled")
Next
Set objWMIService = Nothing
Set objProcess = Nothing
End Sub
'启用服务
Public Sub enableService(service As String)
On Error Resume Next
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\. ootcimv2")
Set colProcessList = objWMIService.ExecQuery("select * from win32_service where name='" & service & "'")
For Each objProcess In colProcessList
objProcess.ChangeStartMode ("Automatic")
Next
Set objWMIService = Nothing
Set objProcess = Nothing
End Sub
呵呵,谢谢
VaTG790i.最好的<a href=http://www.kyfei.com>网站推广软件</a>,
非常好
....................
;ui;普i;uighur;ui;ui;个
在unix网络编程中看到了关于TCP/IP的一些内容,我感觉还是写的不够。正在下载中,一定
下载地址呢