<WriteActionModuleType ID="ComTrade.EMC.Documentum.Windows.ServiceControlManager.ReStartService" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element minOccurs="1" name="ComputerName" type="xsd:string"/>
<xsd:element minOccurs="1" name="ServiceName" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="ComputerName" Selector="$Config/ComputerName$" ParameterType="string"/>
<OverrideableParameter ID="ServiceName" Selector="$Config/ServiceName$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="restartServicel" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>CTDmMPDocumentumMPAgentRestartDataProv.vbs</ScriptName>
<Arguments>"$Config/ComputerName$" "$Config/ServiceName$"</Arguments>
<ScriptBody><Script>Option Explicit
SetLocale("en-us")
Call RestartMain()
Private Function getServiceStatus(ByVal strComputer, ByVal service_name)
Dim objWMIService, colItems, objItem
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2")
If IsObject(objWMIService) = True And IsNull(objWMIService) = False Then
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name = '" & service_name & "'")
If IsObject(colItems) = True And IsNull(colItems) = False And colItems.Count = 1 Then
For Each objItem in colItems
getServiceStatus = objItem.State
Next
Else
getServiceStatus = "NotFound"
End If
Set colItems = Nothing
Else
getServiceStatus="CannotDetermine"
End If
Set objWMIService = Nothing
End Function
Private Function ExecuteShellCommand(ByVal strShellCommand, ByRef ExitCode)
Dim shell, oexec, strPResult
strPResult = ""
Set shell = CreateObject("WScript.Shell")
Set oexec = shell.exec(strShellCommand)
Do While Not oexec.StdOut.AtEndOfStream
strPResult = strPResult & oexec.StdOut.Read(1024)
Loop
ExitCode = oexec.ExitCode
Set oexec = Nothing
Set shell = Nothing
ExecuteShellCommand = strPResult
End Function
Private Function StopService(ByVal service_name, ByRef ExitCode)
StopService = ExecuteShellCommand("sc.exe stop " & Chr(34) & service_name & Chr(34), ExitCode)
End Function
Private Function StartService(ByVal service_name, ByRef ExitCode)
StartService = ExecuteShellCommand("sc.exe start " & Chr(34) & service_name & Chr(34), ExitCode)
End Function
Sub RestartMain()
Dim output, svc_name, ExitCode, sHostname
sHostname = WScript.Arguments(0)
svc_name = WScript.Arguments(1)
output = "Stopping ComTrade MP Agent Service for EMC Documentum ..." & vbNewLine
output = output & StopService(svc_name, ExitCode) & vbNewLine
If (InStr(output, "FAILED") <> 0) Or (InStr(output, "Error") <> 0) Then
WScript.StdErr.WriteLine output
Else
WScript.Echo output
End if
output = "Starting ComTrade MP Agent Service for EMC Documentum ..." & vbNewLine
Dim k, servicestate, svcstat
For k = 0 To 1200
WScript.Sleep (100)
servicestate = getServiceStatus(sHostname, svc_name)
svcstat = UCase(servicestate)
If svcstat= "STOPPED" Or svcstat="NOTFOUND" Or svcstat = "CANNOTDETERMINE" Or svcstat = "RUNNING" Then
Exit For
End If
Next
output = output & StartService(svc_name, ExitCode)
If (InStr(output, "FAILED") <> 0) Or (InStr(output, "Error") <> 0) Or (InStr(output, "The system cannot find the file specified") <> 0) Or (InStr(output, "The network path was not found") <> 0) Then
WScript.StdErr.WriteLine output
Else
WScript.Echo output
End if
End Sub</Script></ScriptBody>
<TimeoutSeconds>900</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="restartServicel"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>