Antigen License Deploy

Antigen_License_Deploy.NoHost (WriteActionModuleType)

Script to copy and deploy a new License.cfg file on the Agent Server

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
Comment{BB8C9694-6EFA-46D3-93EA-99A2C14EFA10}

Member Modules:

ID Module Type TypeId RunAs 
RunScriptAction WriteAction System.Mom.BackwardCompatibility.NoHost.ScriptResponse Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TextLogstring$Config/Parameters/TextLog$TextLogSpecifed whether or not to write to a log file

Source Code:

<WriteActionModuleType ID="Antigen_License_Deploy.NoHost" Accessibility="Internal" Comment="{BB8C9694-6EFA-46D3-93EA-99A2C14EFA10}">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>MomBackwardCompatibility!System.Mom.BackwardCompatibility.AlertGenerationSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="AlertGeneration" type="AlertGenerationType"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="InvokerType" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Parameters" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="TextLog" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TextLog" Selector="$Config/Parameters/TextLog$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="RunScriptAction" TypeID="MomBackwardCompatibility!System.Mom.BackwardCompatibility.NoHost.ScriptResponse">
<AlertGeneration>$Config/AlertGeneration$</AlertGeneration>
<InvokerType>$Config/InvokerType$</InvokerType>
<Body><Script>

'*******************************************************************************************
'*
'* Function:
'* ---------
'*
'* AntigenLicenseDeploy.vbs
'* $Revision: 4 $
'*
'* Purpose:
'* --------
'*
'* Makes a call to Antigenstarter.exe to trigger license Deployment
'*
'* Parameters:
'* -----------
'*
'* TextLog
'*
'* Parameter definitions:
'* ----------------------
'*
'* TextLog =&gt; defines whether this scripts logs entries to a text file under the local
'* Antigen installation folder. Possible Values are true ; false
'*
'*******************************************************************************************

' Constant for controlling text file operations

Const FOR_READING = 1

' Constants registry

Const HIVE = "HKEY_LOCAL_MACHINE\"
Const REG_KEY = "SOFTWARE\Sybari Software\"

' Error Constants
INSTALL_PATH_FAIL = 9501
FILE_NOT_PRESENT = 9502

' Retrieve Script Parameters

TextLogParameter = ScriptContext.Parameters.Get("TextLog")

' Retrieve the local installation path of Antigen

AntigenInstallPath = RetrieveRegValue (REG_KEY &amp; "Antigen For Exchange","InstalledPath", 1)
InstalledProduct = "Antigen For Exchange"

If IsNull(AntigenInstallPath) Then
AntigenInstallPath = RetrieveRegValue (REG_KEY &amp; "Antigen For SMTP","InstalledPath", 1)
InstalledProduct = "Antigen For SMTP"
End If

If IsNull(AntigenInstallPath) Then
WriteMOMEvent "TASK ERROR: Unable To Retrieve Antigen Installation Path", 1, INSTALL_PATH_FAIL
ScriptContext.Quit
End If

MOMInstallPath = RetrieveRegValue ("SOFTWARE\Microsoft\Microsoft Operations Manager\2.0\Setup","InstallDirectory", 1)

If IsNull(MOMInstallPath) Then
WriteMOMEvent "TASK ERROR: Unable To Retrieve MOM Agent Installation Path", 1, INSTALL_PATH_FAIL
ScriptContext.Quit
End If



' Create Log folder under Antigen installation folder

If TextLogParameter = "true" then
CreateLogFolder()
End If


WriteLog "NULL"
WriteLog "Beginning Execution of LicenseDeploy Script"

'Copy License.cfg file to the Antigen Installation folder

boolResult = CopylicenseFile (MOMInstallPath, AntigenInstallPath)


If boolResult Then

strParam = " l"
strCommand = """" &amp; AntigenInstallPath &amp; "\AntigenStarter.exe" &amp; """"

intResult = ShellExecute(strCommand,strParam)

WriteLog "AntigenStarter has deployed the license.cfg file"

Else
WriteLog "ERROR: No license.cfg file is present for deployment"
WriteMOMEvent "TASK ERROR: No License.cfg file is present for deployment", 1, FILE_NOT_PRESENT

End If



'********************************************************************
'*
'* Function: RetrieveRegValue
'*
'* Purpose: Retrieves String Value from Registry
'*
'********************************************************************

Function RetrieveRegValue (Key, strValueName, intValueType)

' intValueType -&gt; 1 = String Value
' -&gt; 2 = DWORD Value

const HKEY_LOCAL_MACHINE = &amp;H80000002
Dim strServerName
Dim objReg
Dim strRegValue


On Error Resume Next
Err.Clear
Set objReg=GetObject("winmgmts:\root\default:StdRegProv")
If Err.Number &lt;&gt; 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 &lt;&gt; 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)

set wshShell = CreateObject ("wscript.shell")

wshShell.run Command &amp; Parameter,,false

Set wshShell = Nothing

End Function


'***********************************************************************
'*
'* Function: CreateLogFolder()
'*
'* Purpose: Creates Log subfolder under Antigen
'*
'***********************************************************************

Function CreateLogFolder ()

Dim objFSO
set objFSO = CreateObject ("Scripting.FileSystemObject")

If objFSO.FolderExists(AntigenInstallPath &amp; "\MOMLogs") = 0 then
objFSO.CreateFolder(AntigenInstallPath &amp; "\MOMLogs")
End If

Set objFSO = Nothing

End Function

'***********************************************************************
'*
'* Function: CopyLicenseFile()
'*
'* Purpose: Copy License File to Antigen folder
'*
'***********************************************************************

Function CopyLicenseFile (MomPath, AntigenPath)

Dim LicenseFile
Dim objFSO
set objFSO = CreateObject ("Scripting.FileSystemObject")


LicenseFile = MOMPath &amp; "Downloaded Files\" &amp; ScriptContext.ManagementGroupName &amp; "\License.cfg"

If objFSO.FileExists(LicenseFile) Then
objFSO.CopyFile LicenseFile, AntigenPath &amp; "\", True
Set objFSO = Nothing
CopylicenseFile = True
Else
Set objFSO = Nothing
CopyLicenseFile = False
End If

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 &amp; "\MOMLogs\" &amp; "Tasks.log", 8, False)


' If log file doesn't exist - create it
If Err.Number &lt;&gt; 0 Then
Set objf = objfs.CreatetextFile(AntigenInstallPath &amp; "\MOMLogs\" &amp; "Tasks.log", False)
Err.Clear
End If

If strLogText = "NULL" then
objf.WriteLine("")
Else
strTimeStamp = Date &amp; " " &amp; Time &amp; " "
objf.WriteLine(strTimeStamp &amp; strLogText)
End If

Set objfs = Nothing
Set objf = Nothing
End If

End Function


'***********************************************************************
'*
'* Function: WriteMOMEvent()
'*
'* Purpose: Writes events to MOM EventLog
'*
'***********************************************************************

Function WriteMOMEvent(EventMessage, EventType, EventNumber)

Dim objEvt
Set objEvt = ScriptContext.CreateEvent

objEvt.Message = EventMessage
objEvt.EventType = EventType
objEvt.EventNumber = EventNumber
ScriptContext.Submit(objEvt)

set objEvt = Nothing

End Function</Script></Body>
<Language>VBScript</Language>
<Name>Antigen License Deploy</Name>
<Parameters>
<Parameter>
<Name>TextLog</Name>
<Value>$Config/Parameters/TextLog$</Value>
</Parameter>
</Parameters>
<ManagementPackId>[Microsoft.Antigen.v9,,1.0.0.1]</ManagementPackId>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="RunScriptAction"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>SystemLibrary!System.BaseData</InputType>
</WriteActionModuleType>