AntigenInstallPath = RetrieveRegValue ("SOFTWARE\Sybari Software\Antigen For Exchange","InstalledPath", 1)
If IsNUll(AntigenInstallPath) Then
WriteMOMEvent "TASK ERROR: Unable to retrieve Antigen for Exchange installation path", 1
ScriptContext.Quit
End If
' Create Log folder under Antigen installation folder
If TextLogParameter = "true" then
CreateLogFolder()
End If
WriteLog "NULL"
WriteLog "Beginning Execution of Manual Scan Schedule Script"
If ScanIDParameter = "<Enter Scan Job ID>" Then
WriteLog "TASK ERROR: Scan Job ID not specified"
WriteMOMEvent "TASK ERROR: Scan Job ID not specified", 1
ScriptContext.Quit
End If
strParam = AtCommand & " " & """" & AntigenInstallPath & "\AntigenStarter.exe" & """" & " s" & ScanIDParameter & """"
strCommand = "at "
WriteLog "Manual Scan Job ID = " & ScanIDParameter
WriteLog "Schedule Inteval = " & IntervalParameter & " @ " & StartTimeParameter & " on " & StartDayParameter
WriteLog "Command: " & strCommand & strParam
iResult = ShellExecute(strCommand, strParam)
If iResult <> 0 Then
WriteLog "TASK ERROR: Invalid schedule parameters specified. Failed to schedule manual scan."
WriteMOMEvent "TASK ERROR: Invalid schedule parameters specified. Failed to schedule manual scan.", 1
End If
WriteLog "Scheduling of Manual Scan job complete"
'********************************************************************
'*
'* Function: BuildATCommand
'*
'* Purpose: Retrieves String Value from Registry
'*
'********************************************************************
Function BuildATCommand (Interval, StartDay, StartTime)
Select Case Interval
Case "monthly"
BuildATCommand = StartTime & " /every:" & StartDay
Case "weekly"
BuildATCommand = StartTime & " /every:" & StartDay
Case "daily"
BuildATCommand = StartTime & " /every:" & "M,T,W,Th,F,S,Su"
Case "once"
If StartDay = "today" then
BuildATCommand = StartTime
Else
BuildATCommand = StartTime & " /next:" & StartDay
End If
End Select
End Function
'********************************************************************
'*
'* Function: RetrieveRegValue
'*
'* Purpose: Retrieves String Value from Registry
'*
'********************************************************************
Function RetrieveRegValue (Key, strValueName, intValueType)
' intValueType -> 1 = String Value
' -> 2 = DWORD Value
const HKEY_LOCAL_MACHINE = &H80000002
Dim strServerName
Dim objReg
Dim strRegValue
On Error Resume Next
Err.Clear
Set objReg=GetObject("winmgmts:\root\default:StdRegProv")
If Err.Number <> 0 Then
Err.Clear
strRegValue = NULL
Else
Select Case intValueType
Case 1
strErr = objReg.GetStringValue (HKEY_LOCAL_MACHINE, Key, strValueName, strRegValue)
Case 2
strErr = objReg.GetDWORDValue (HKEY_LOCAL_MACHINE, Key, strValueName, strRegValue)
End Select
' if reading the registry fails via wmi return error
If strErr <> 0 then
strRegValue = NULL
End If
End If
Set objReg = Nothing
RetrieveRegValue = strRegValue
End Function
'***********************************************************************
'*
'* Function: ShellExecute()
'*
'* Purpose: Sets up call to ANTUTIL for switching hooking mode
'*
'***********************************************************************
Function ShellExecute (Command, Parameter)
Dim bWaitOnReturn
Dim iReturn
bWaitOnReturn = true
set wshShell = CreateObject ("wscript.shell")
iReturn = wshShell.run(Command & Parameter,,bWaitOnReturn)
Dim objFSO
set objFSO = CreateObject ("Scripting.FileSystemObject")
If objFSO.FolderExists(AntigenInstallPath & "\MOMLogs") = 0 then
objFSO.CreateFolder(AntigenInstallPath & "\MOMLogs")
End If
Set objFSO = Nothing
End Function
'***********************************************************************
'*
'* Function: WriteLog()
'*
'* Purpose: Writes script activity and errors to a log file
'*
'***********************************************************************
Function WriteLog (strLogText)
If TextLogParameter = "true" Then
Dim objfs
Dim objf
Dim strTimeStamp
On Error Resume Next
Err.Clear
Set objfs = CreateObject("Scripting.FileSystemObject")
Set objf = objfs.OpentextFile(AntigenInstallPath & "\MOMLogs\" & "Tasks.log", 8, False)
' If log file doesn't exist - create it
If Err.Number <> 0 Then
Set objf = objfs.CreatetextFile(AntigenInstallPath & "\MOMLogs\" & "Tasks.log", False)
Err.Clear
End If
If strLogText = "NULL" then
objf.WriteLine("")
Else
strTimeStamp = Date & " " & Time & " "
objf.WriteLine(strTimeStamp & strLogText)
End If
End If