'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 < 2 then
Wscript.Quit -1
End if
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 '" & TaskOutputFile & "'"
strAddFAILText = " - Check BackUp File location" & Chr(10) & strTextStream
Case "2"
strAddOKText = "Task Completed Successfully - DNS Cache Cleared"
strAddFAILText = " - To Clear DNS Cache" & Chr(10) & strTextStream
Case "3"
strAddOKText = strTextStream & Chr(10) & Chr(10) & "Task Completed Successfully"
strAddFAILText = " - To obtain Active Firewall Session" & Chr(10) & strTextStream
Case "4"
strAddOKText = strTextStream & Chr(10) & Chr(10) & "Task Completed Successfully"
strAddFAILText = " - To obtain DNS Cache" & Chr(10) & strTextStream
Case "5"
strAddOKText = strTextStream & Chr(10) & Chr(10) & "Task Completed Successfully"
strAddFAILText = " - To obtain DNS Cache" & Chr(10) & strTextStream
Case "6"
strAddOKText = strTextStream & Chr(10) & Chr(10) & "Task Completed Successfully"
strAddFAILText = " - To obtain ADAM Sites Links" & Chr(10) & strTextStream
Case "7"
strAddOKText = strTextStream & Chr(10) & Chr(10) & "Task Completed Successfully"
strAddFAILText = " - To obtain Adam Sites and Servers" & Chr(10) & strTextStream
End Select
If InStr(1,strTextStream,"Error:") = 0 Then
strOutPutStream = strAddOKText
Else
strOutPutStream = "Task Fail" & 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 """ & QuoteWrap(strCmdToUse) & " " & QuoteWrap(strOptionToUse) & " " & QuoteWrap(TaskOutputFile) &""""
Else
ncControlcommand = "cmd.exe /C " & 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 '" & strInstallPath & strCmdToUse & "'"
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 & output.ReadAll
else
exit Do
end if
Loop
strOutPut = output.ReadAll
If oExec.ExitCode <> 0 Then
strOutPut = Replace(strOutPut,"Failed to find error text message. error is 80070020","")
strOutPut = "Error: " & 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 & "\"
GetConsoleExePath = strInstallPath
end Function
Function QuoteWrap(myString)
If (myString <> "") And (left(mySTring,1) <> Chr(34)) And (Right(myString,1) <> Chr(34)) Then
QuoteWrap = Chr(34) & myString & Chr(34)
Else
QuoteWrap = myString
End If
End Function