Microsoft.Forefront.TMG.General.Tasks (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
Script WriteAction Microsoft.Windows.ScriptWriteAction Default

Overrideable Parameters:

IDParameterTypeSelector
FileOutputstring$Config/FileOutput$
TimeoutSecondsint$Config/TimeoutSeconds$

Source Code:

<WriteActionModuleType ID="Microsoft.Forefront.TMG.General.Tasks" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element name="TaskOption" type="xsd:string"/>
<xsd:element name="FileOutput" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="FileOutput" Selector="$Config/FileOutput$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>Microsoft.Forefront.TMG.GeneralTasks.vbs</ScriptName>
<Arguments>"$Config/TaskOption$" "$Config/FileOutput$"</Arguments>
<ScriptBody><Script>

'Copyright (c) Microsoft Corporation. All rights reserved.
'*******************************************************************************
' $ScriptName: "General TMG Tasks" $
'
' Purpose - This script Execute General Tools Tasks.
'
' Parameters
' "TaskOption" = This is the Task Option (1-7)
' "FileOutput" = This is the File name To Use
'
' $File: Microsoft.Forefront.TMG.GeneralTasks.vbs $
'
'*************************************************************************

SetLocale("en-us")

Dim strCmdToUse, strOptionToUse, strInstallPath
Dim oParams, TaskOption, TaskOutputFile, boolAddOptToCmd

Set oParams = WScript.Arguments
If oParams.Count &lt; 2 then
Wscript.Quit -1
End if

TaskOption = oParams(0)
TaskOutputFile = oParams(1)
call GetTaskByOption
call ExecuteISACmd()


Function GetTaskByOption()
Select Case TaskOption
Case "1"
strCmdToUse = "AdamSites.exe"
strOptionToUse = "Backup"
boolAddOptToCmd = true
Case "2"
strCmdToUse = "DNSTools.exe /C"
strOptionToUse = ""
boolAddOptToCmd = false
Case "3"
strCmdToUse = "netsh tmg show connections"
strOptionToUse = ""
boolAddOptToCmd = false
Case "4"
strCmdToUse = "DNSTools.exe /D"
strOptionToUse = ""
boolAddOptToCmd = false
Case "5"
strCmdToUse = "DNSTools.exe /DZ"
strOptionToUse = ""
boolAddOptToCmd = false
Case "6"
strCmdToUse = "AdamSites.exe"
strOptionToUse = "SiteLinks"
boolAddOptToCmd = true
Case "7"
strCmdToUse = "AdamSites.exe"
strOptionToUse = "Sites"
boolAddOptToCmd = true
End Select
End Function

Function GetOutPut(strTextStream)
Dim strOutPutStream, strAddOKText, strAddFAILText
Select Case TaskOption
Case "1"
strAddOKText = "Task Completed Successfully - New BackUp File Created in '" &amp; TaskOutputFile &amp; "'"
strAddFAILText = " - Check BackUp File location" &amp; Chr(10) &amp; strTextStream
Case "2"
strAddOKText = "Task Completed Successfully - DNS Cache Cleared"
strAddFAILText = " - To Clear DNS Cache" &amp; Chr(10) &amp; strTextStream
Case "3"
strAddOKText = strTextStream &amp; Chr(10) &amp; Chr(10) &amp; "Task Completed Successfully"
strAddFAILText = " - To obtain Active Firewall Session" &amp; Chr(10) &amp; strTextStream
Case "4"
strAddOKText = strTextStream &amp; Chr(10) &amp; Chr(10) &amp; "Task Completed Successfully"
strAddFAILText = " - To obtain DNS Cache" &amp; Chr(10) &amp; strTextStream
Case "5"
strAddOKText = strTextStream &amp; Chr(10) &amp; Chr(10) &amp; "Task Completed Successfully"
strAddFAILText = " - To obtain DNS Cache" &amp; Chr(10) &amp; strTextStream
Case "6"
strAddOKText = strTextStream &amp; Chr(10) &amp; Chr(10) &amp; "Task Completed Successfully"
strAddFAILText = " - To obtain ADAM Sites Links" &amp; Chr(10) &amp; strTextStream
Case "7"
strAddOKText = strTextStream &amp; Chr(10) &amp; Chr(10) &amp; "Task Completed Successfully"
strAddFAILText = " - To obtain Adam Sites and Servers" &amp; Chr(10) &amp; strTextStream
End Select

If InStr(1,strTextStream,"Error:") = 0 Then
strOutPutStream = strAddOKText
Else
strOutPutStream = "Task Fail" &amp; strAddFAILText
End If

GetOutPut = strOutPutStream
End Function

Function ExecuteISACmd()
Dim ncControlcommand
Dim oShell
Dim curDir
Dim strExecOut

Set oShell = CreateObject("WScript.Shell")
oShell.CurrentDirectory = GetConsoleExePath()
curDir = oShell.CurrentDirectory
If boolAddOptToCmd = true Then
ncControlcommand = "cmd.exe /C """ &amp; QuoteWrap(strCmdToUse) &amp; " " &amp; QuoteWrap(strOptionToUse) &amp; " " &amp; QuoteWrap(TaskOutputFile) &amp;""""
Else
ncControlcommand = "cmd.exe /C " &amp; QuoteWrap(strCmdToUse)
End If
strExecOut = RunCmd(ncControlcommand)

If InStr(1,strExecOut,"is not recognized as an internal or external command") = 0 Then
WScript.Echo GetOutPut(strExecOut)
Else
WScript.Echo "Tool is not Installed, please check in location '" &amp; strInstallPath &amp; strCmdToUse &amp; "'"
End If

ExecuteISACmd = strExecOut
End Function

Function RunCmd(CmdString)
Dim wshshell
Dim oExec
Dim output
Dim strOutPut

Set wshshell = CreateObject("WScript.Shell")
Set oExec = wshshell.Exec(CmdString)
WScript.Sleep 5000
Set output = oExec.StdOut
Do While oExec.Status = 0
WScript.Sleep 100
if output.AtEndOfStream = false then
strOutPut = strOutPut &amp; output.ReadAll
else
exit Do
end if
Loop

strOutPut = output.ReadAll

If oExec.ExitCode &lt;&gt; 0 Then
strOutPut = Replace(strOutPut,"Failed to find error text message. error is 80070020","")
strOutPut = "Error: " &amp; strOutPut
End If

Set wshshell = Nothing
RunCmd = strOutPut
End Function

Function GetConsoleExePath()
Dim objRoot, objSrv
Set objRoot = CreateObject("FPC.Root")
Set objSrv = objRoot.GetContainingServer()
strInstallPath = objSrv.InstallationDirectory &amp; "\"
GetConsoleExePath = strInstallPath
end Function

Function QuoteWrap(myString)
If (myString &lt;&gt; "") And (left(mySTring,1) &lt;&gt; Chr(34)) And (Right(myString,1) &lt;&gt; Chr(34)) Then
QuoteWrap = Chr(34) &amp; myString &amp; Chr(34)
Else
QuoteWrap = myString
End If
End Function

</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>