<DataSourceModuleType ID="AD_Execute_Support_Tool.DataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:int"/>
<xsd:element name="CommandInitialDirectory" type="xsd:string"/>
<xsd:element name="ApplicationName" type="xsd:string"/>
<xsd:element name="Parameters" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="CommandInitialDirectory" Selector="$Config/CommandInitialDirectory$" ParameterType="string"/>
<OverrideableParameter ID="ApplicationName" Selector="$Config/ApplicationName$" ParameterType="string"/>
<OverrideableParameter ID="Parameters" Selector="$Config/Parameters$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/AD_Execute_Support_Tool.vbs$ $Config/CommandInitialDirectory$ $Config/ApplicationName$ $Config/Parameters$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>AD_Execute_Support_Tool.vbs</Name>
<Contents><Script>
'*************************************************************************
' Script Name - AD Execute Support Tool
'
' Purpose - Runs a command line task and puts the output into an event
'
' Parameters - ApplicationName - The name of the executable
' CommandInitialDirectory - the drive\path on the target
' machine where <Application Name> is located
' Parameters - the parameters that will be passed to
' <Application Name> as part of a task
'
'
' (c) Copyright 2008, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************
Class Error
Public Description
Public Number
Public Source
Sub Init(oErr)
Description = oErr.Description
Number = oErr.Number
Source = oErr.Source
End Sub
Sub Raise(strDescription)
Err.Raise Number, Source, strDescription & GetErrorString(Number, Description)
End Sub
End Class
Dim oError
Set oError = new Error
On Error Resume Next
Dim oParams, strCommandInitialDirectory, strApplicationName, strParameters
' Other Variables
Set oParams = WScript.Arguments
if oParams.Count < 3 then
Wscript.Quit -1
End if
DoExecuteTask
If Err.number <> 0 Then
CreateEvent EVENT_ID_TASK_OUTPUT, EVENT_TYPE_WARNING, "An error occurred while executing '" & _
SCRIPT_NAME & "'." & vbCrLf & "The error returned was: " & GetErrorString(Err.number, Err.Description)
End If
If Len(strEXE) = 0 Then
Err.Raise E_INVALIDARG, "ExeName", "One or more of the specified parameters is invalid. " & _
"Please check the script parameters and try the task again."
End If
' Make sure we have a trailing \ in the path
If Len(strPath) > 0 Then
If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
End If
Dim iExitCode
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
strPath = oShell.ExpandEnvironmentStrings(strPath)
Dim oExec, strMessage
On Error Resume Next
Set oExec = oShell.Exec(strPath & strEXE & " " & strCommandLineArgs)
strMessage = strPath & strEXE & " " & strCommandLineArgs & vbCrLf & vbCrLf
If Err.number = E_FILENOTFOUND Or Err.number = E_INVALIDPATH Then
strMessage = strEXE & " " & strCommandLineArgs & vbCrLf & vbCrLf
Set oExec = oShell.Exec(strEXE & " " & strCommandLineArgs)
If Err.number = E_FILENOTFOUND Or Err.number = E_INVALIDPATH Then
strMessage = "'" & strEXE & "' could not be found in the path "
If Len(strPath) > 0 Then
strMessage = strMessage & " or at '" & strPath & "' "
End If
strMessage = strMessage & "on the target computer. Ensure that '" & _
strExe & "' is installed and/or update the " & _
"""Command initial directory"" script parameter with the appropriate " & _
"location of this utility on the target computer. " & _
"'" & strEXE & "' is part of the Windows Server optional support " & _
"utilities located on the Windows Server installation CD."
CreateEvent EVENT_ID_TASK_OUTPUT, EVENT_TYPE_WARNING, strMessage
WScript.Quit
ElseIf Err.number <> 0 Then
oError.Init Err
On Error Goto 0
oError.Raise "Failed to execute '" & strEXE & " " & strCommandLineArgs & "'."
End If
ElseIf Err.number <> 0 Then
oError.Init Err
On Error Goto 0
oError.Raise "Failed to execute '" & strPath & strEXE & " " & strCommandLineArgs & "'."
End If
Dim iBlankLines
Do
Dim strLine
strLine = oExec.stdout.ReadLine()
If Len(strLine) = 0 Then
iBlankLines = iBlankLines + 1
Else
Do
If Asc(Right(strMessage, 1)) <> 13 Then
strMessage = strMessage & vbCrLf
End If
iBlankLines = iBlankLines - 1
Loop While iBlankLines > 0
strMessage = strMessage & strLine
iBlankLines = 0
End If
If Len(strMessage) > MAX_EVENT_TEXT_LENGTH Then
strMessage = strMessage & vbCrLf & vbCrLf & _
"Output from this task is continued in the next event."
CreateEvent EVENT_ID_TASK_OUTPUT, EVENT_TYPE_INFORMATION, strMessage
strMessage = "Output continued from previous event." & vbCrLf & vbCrLf
End If
Loop While (oExec.Status = 0) Or (oExec.Stdout.AtEndOfStream = False)
iExitCode = oExec.ExitCode
End If
WScript.echo strMessage
If iExitCode = 0 Then
CreateEvent EVENT_ID_TASK_OUTPUT, EVENT_TYPE_INFORMATION, strMessage
Else
CreateEvent EVENT_ID_TASK_OUTPUT, EVENT_TYPE_WARNING, strMessage
End If
End Sub
'******************************************************************************
Sub CreateEvent(lngEventID, lngEventType, strMessage)
'
' Purpose: Creates a MOM event
'
' Parameters: lngEventID, the ID for the event
' lngEventType, the severity for the event. See constants at head of file
' strMessage, the message for the event
'
' Return: nothing
'
On Error Resume Next
oAPI.LogScriptEvent "AD Execute Support Tool", lngEventID, lngEventType, strMessage
End Sub
'******************************************************************************
Function GetErrorString(lErr, strErr)
'
' Purpose: Attempts to find the description for an error if an error with
' no description is passed in.
'
' Parameters: oErr, the error object
'
' Return: String, the description for the error. (Includes the error code.)
'
On Error Resume Next
If 0 >= Len(strErr) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &HFFFF0000
Const HiWord8007 = &H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF
If (lErr And ErrorMask) = HiWord8007 Then
' Attempt to use 'net helpmsg' to get a description for the error.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " & (lErr And LoWordMask))
Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i < 5)
strErr = strMessage
End If
End If
End If
GetErrorString = vbCrLf & "'" & strErr & "' (0x" & Hex(lErr) & ")"
End Function