EDC.Base.AsyncCmdLine.WriteAction (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
WA1 WriteAction System.CommandExecuter Default

Overrideable Parameters:

IDParameterTypeSelector
HideWindowstring$Config/HideWindow$

Source Code:

<WriteActionModuleType ID="EDC.Base.AsyncCmdLine.WriteAction" Accessibility="Public" Batching="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>System!System.ParamListSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CmdLine" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HideWindow" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SecureInput" minOccurs="0" maxOccurs="1">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="256"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="HideWindow" Selector="$Config/HideWindow$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="WA1" TypeID="System!System.CommandExecuter">
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>/nologo RunCmdLineAsync.vbs "$Config/CmdLine$" $Config/HideWindow$</CommandLine>
<SecureInput>$Config/SecureInput$</SecureInput>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>RunCmdLineAsync.vbs</Name>
<Contents><Script>
Option Explicit
'************************************************************************************************************
' Disclaimer
'
' This sample script is not supported under any Microsoft standard support program or service. This sample
' script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties
' including, without limitation, any implied warranties of merchantability or of fitness for a particular
' purpose. The entire risk arising out of the use or performance of this sample script and documentation
' remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation,
' production, or delivery of this script be liable for any damages whatsoever (including, without limitation,
' damages for loss of business profits, business interruption, loss of business information, or other
' pecuniary loss) arising out of the use of or inability to use this sample script or documentation, even
' if Microsoft has been advised of the possibility of such damages.
'
'***********************************************************************************************************
'* RunCmdLineAsync.vbs v1.1 Version 20090518
'*
'* Runs a given cmd line asynchronously.
'*
'* Version for Operations Manager 2007
'*
'* JM
'******************************************************************************************************
'Const SCRIPT_NAME = "RunCmdLineAsync.vbs"
Const SCRIPT_VERSION = "1.1"

'Event Constants
Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

Const EVENT_ID_SUCCESS = 1000 'Use IDs in the range 1 - 1000
Const EVENT_ID_SCRIPTERROR = 999 'Then you can use eventcreate.exe to test the MP

Call Main

'********************************************************************************
' PROCEDURE: Main
' DESCRIPTION: Called on script start. Read the script's cmd line arguments
' and build the cmd line that shall be executed asynchronously.
' The first argument must be the full name of the script which
' shall be started asynchronously.
' PARAMETERS: -
'******************************************************************************
Private Sub Main()

Dim objMomScriptAPI 'As MOM.ScriptAPI
Dim objArguments 'As WScript.Arguments
Dim strCmdLine 'As String
Dim strTmp 'As String
Dim blnHide 'As Boolean
Dim intHide 'As Integer
Dim objFSO 'As Scripting.FileSystemObject
Dim objWSHShell 'As WScript.Shell
Dim i 'As Long
Dim blnUseWMI 'As Boolean

Call SetLocale("en-us")
Set objMomScriptAPI = CreateObject("MOM.ScriptAPI")
Set objWSHShell = CreateObject("WScript.Shell")

'Get the arguments
Set objArguments = WScript.Arguments

If objArguments.Count &gt; 0 Then
For i = 0 To objArguments.Count - 1
strTmp = strTmp &amp; ";" &amp; objArguments(i)
Next 'i
End If

Call objMomScriptAPI.LogScriptEvent(WScript.ScriptName &amp; " " &amp; SCRIPT_VERSION, EVENT_ID_SUCCESS, EVENT_TYPE_INFORMATION, _
"The script was called using the following arguments: " &amp; vbCrLf &amp; strTmp)


'If there is at least one argument build the command line.
'It is assumed that the first argument is the full name of the script
'which shall be started asynchronously.
If objArguments.Count &gt; 0 Then

'The script name must be the first argument
strCmdLine = objWSHShell.ExpandEnvironmentStrings(objArguments(0))

On Error Resume Next

'The 2nd argument is optional
'If set to true the started window will be hidden.
If objArguments.Count &gt; 1 Then
blnHide = CBool(objArguments(1))
If blnHide Then intHide = 0 Else intHide = 1
Else
'Default is to display the new app
intHide = 1
End If

'Run the cmd line but do not wait.
Call WScript.Echo("Executing cmd line '" &amp; strCmdLine &amp; "'...")
Call objWSHShell.Run(strCmdLine, intHide, False)

'If the error number is 0 then the cmd was issued successfully
If Err.Number = 0 Then
Call objMomScriptAPI.LogScriptEvent(WScript.ScriptName &amp; " " &amp; SCRIPT_VERSION, EVENT_ID_SUCCESS, EVENT_TYPE_INFORMATION, _
"Executed the following cmd line asynchronously: " &amp; vbCrLf &amp; strCmdLine)
Else
Call objMomScriptAPI.LogScriptEvent(WScript.ScriptName &amp; " " &amp; SCRIPT_VERSION, EVENT_ID_SCRIPTERROR, EVENT_TYPE_ERROR, _
"Error! Could not execute the following cmd line asynchronously: " &amp; vbCrLf &amp; strCmdLine)
End If
Else
Call objMomScriptAPI.LogScriptEvent(WScript.ScriptName &amp; " " &amp; SCRIPT_VERSION, EVENT_ID_SCRIPTERROR, EVENT_TYPE_WARNING, _
"The arguments are missing.")
End If

End Sub
</Script></Contents>
<Unicode>true</Unicode>
</File>
</Files>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="WA1"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>