使用VBS获取当前计算机上开启的服务

'获得当前系统服务
Dim oArgs, strServerName, oServiceSet, oWshNetwork

Set oArgs = WScript.Arguments
If oArgs.Count > 0 Then
   strServerName = trim(oArgs(0))
Else
   strServerName = "LocalHost"
End If
Set oServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strServerName & "/root/cimv2").InstancesOf("Win32_Service")
If strServerName = "LocalHost" Then
   Set oWshNetwork = WScript.CreateObject("WScript.Network")
   WScript.Echo  oWshNetwork.ComputerName & " 系统服务信息如下:"
   Set oWshNetwork = Nothing
Else
   WScript.Echo strServerName & " 系统服务信息如下:"
End If
WScript.Echo String(75, "_")
For each Service in oServiceSet
 WScript.Echo "      显示名称:" & Service.Description & "服务名称:" & Service.Name &" 当前状态:" & Service.State

Next
WScript.Echo String(75, "_")
Set oServiceSet = Nothing


WScript.Echo String(75, "_")
Set oServiceSet = Nothing

 

转载于:https://www.cnblogs.com/greystar/archive/2004/09/01/2235596.html

你可能感兴趣的:(使用VBS获取当前计算机上开启的服务)