'获得当前系统服务
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