SetLocale("en-us")
HandleErrorContinue("Cannot set en-us locale")
Dim WShell : Set WShell = CreateObject("wscript.shell")
HandleErrorWithoutPropertyBag("CreateObject('wscript.shell')")
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
HandleErrorWithoutPropertyBag("CreateObject('Scripting.FileSystemObject')")
Dim oAPI : Set oAPI = CreateObject("MOM.ScriptAPI")
HandleErrorWithoutPropertyBag("MOM.ScriptAPI")
Dim Args : Set Args = WScript.Arguments
if Args.Count < 3 then
WScript.Quit
end if
Dim ServiceName : ServiceName = Args(0)
Dim safeEnable : safeEnable = Args(1)
Dim discoveryEnable : discoveryEnable = Args(2)
Dim oMOMBag : Set oMOMBag = oAPI.CreatePropertyBag()
HandleErrorWithoutPropertyBag("Cannot create PropertyBag")
If Not safeEnable or Not discoveryEnable Then
ReturnWithoutObject()
End If
Dim WMI_NAMESPACE : WMI_NAMESPACE = "winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2"
Dim WMI_SERVICE : WMI_SERVICE = "SELECT * FROM Win32_Service WHERE Name = '" & ServiceName & "'"
Dim objWMI : Set objWMI = GetObject(WMI_NAMESPACE)
HandleError("Cannot connect to WMI")
Dim serviceObj : Set serviceObj = objWMI.ExecQuery(WMI_SERVICE)
HandleError("Cannot retrieve windows service from WMI: " & ServiceName)
Dim found : found = FALSE
For Each service in serviceObj
Call oMOMBag.AddValue("Name", service.Name)
Call oMOMBag.AddValue("PathName", service.PathName)
Call oMOMBag.AddValue("DisplayName", service.DisplayName)
If service.Description <> null and Len(Trim(service.Description)) > 0 Then
Call oMOMBag.AddValue("Description", service.Description)
Else
Call oMOMBag.AddValue("Description", "Empty")
End If
Call oMOMBag.AddValue("IsEmptyInstance", "false")
found = TRUE
Next
HandleError("Cannot create property bag data")
If NOT found Then
ReturnWithoutObject()
End If
Call oAPI.Return(oMOMBag)
Function ReturnWithoutObject()
Call oMOMBag.AddValue("IsEmptyInstance", "true")
Call oAPI.Return(oMOMBag)
Wscript.Quit 0
End Function
Sub HandleError(customMessage)
If Not (Err.number = 0) Then
LogError customMessage
ReturnWithoutObject
End If
End Sub
Sub HandleErrorWithoutPropertyBag(customMessage)
If Not (Err.number = 0) Then
LogError customMessage
Wscript.Quit 0
End If
End Sub
Function HandleErrorContinue(customMessage)
HandleErrorContinue = False
If Not (Err.number = 0) Then
LogError customMessage
Err.Clear
HandleErrorContinue = True
End If
End Function
Sub LogError(customMessage)
Dim msg
If Not (Err.number = 0) Then
msg = Replace(" Error: #P1# Description: #P2# ", "#P1#", CStr(Err.number) )
msg = Replace(msg, "#P2#", Err.Description )
msg = customMessage & VbCrLf & msg & VbCrLf
If UCase(Hex(Err.number)) = UCase("80041006") Then
msg = msg & "WMI Error. Not enough memory for the operation." & VbCrLf
End If
WScript.StdOut.WriteLine msg
msg = msg & " [" & ScriptInfo() & "]"
LogEvent msg, 1
End If
End Sub
Function ScriptInfo()
Dim commandLineInfo : commandLineInfo = WScript.ScriptFullName
Dim argument
For Each argument In WScript.Arguments
commandLineInfo = commandLineInfo & " """ & argument & """"
Next
ScriptInfo = commandLineInfo
End Function
Sub LogEvent (message, eventType)
Dim errorEventId : errorEventId = 20000
Dim oAPI0 : Set oAPI0 = CreateObject("MOM.ScriptAPI")
Call oAPI0.LogScriptEvent("AVIcode .NET Enterprise Management Pack for OpsMgr 2007", errorEventId, eventType, message)
End Sub </Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="DataSource"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>