Thanks for the hint.
But the KAV password is hard coded in the procedure... I guess it's easy enough to change it...
The thing is, in my ongoing research for perfection, I was trying to find a way to read the password from the KSUBSCRIBER database into a variable.
Unfortunately, Kaseya does not allow Get Variable (constant Value) to receive the result of a SQL command:
Parameter 1: 2
Parameter 2: +++SQLCMD:select UninstallPassword from kav.KasperskyFeature where agentguid = +++GETVARGUID:
Parameter 3: UninstPwd
Continue On Fail: False
OS Type: 0 (All Windows operating systems)
You cannot directly type it in the editor ( it refuses to save)
You cannot even trick the system by importing the procedure from a XML file (it tells you the syntax is reserved for system scripts)
I guess I could try by setting a Script ID below 999, bu I don't want to go that far.
Maybe I'll ask as a feature request the ability to type SQL query, the condition being it has to be a simple SELECT statement (i.e. no UPDATE, DELETE, TRUNCATE, DROP, etc...)
Anyway, I found a better way to do it...
Based on the principle that Kaseya already does the job for you (when you click on the Update function in KAV) I went in the database and found the system procedure doing the job: "KAV: Update License File" script ID 343. Below is the content of the procedure.
KAV: Update License File (Script ID: 343)
if True THEN Get Variable
Parameter 1: 10
Parameter 2: null
Parameter 3: agentTempDir
Continue On Fail: False
OS Type: 0 (All Windows operating systems)
THEN Write File
Parameter 1: #agentTempDir#\KAV\kav_command_addkey.lua
Parameter 2: vsahiddenfiles\kav\scripts\kav_command_addkey.lua
Parameter 3: null
Continue On Fail: False
OS Type: 0 (All Windows operating systems)
THEN Write File
Parameter 1: #agentTempDir#\KAV\update.key
Parameter 2: vsahiddenfiles\kav\Update.key
Parameter 3: null
Continue On Fail: False
OS Type: 0 (All Windows operating systems)
THEN Run DLL Command
Parameter 1: KaLua.dll
Parameter 2: -componentId KAV -runLuaScript "#agentTempDir#\KAV\kav_command_addkey.lua"
Parameter 3: 0
Continue On Fail: False
OS Type: 0 (All Windows operating systems)
So I prepared my procedure in the Kaseya Editor...
Then I exported it (and deleted from the Kaseya UI, that's to facilitate later import),
Then I modified the exported XML file to add a call to this script 343
<?xml version="1.0" encoding="utf-8"?>
<ScriptExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.kaseya.com/vsa/2008/12/Scripting">
<Procedure name="Refresh KAV Key" treePres="3" id="1117092692" folderId="860904637752521" treeFullPath="0Live.Automatic Remediation.KAV">
<Body description="">
<Statement name="GetVariable" continueOnFail="false">
<Parameter xsi:type="EnumParameter" name="VariableType" value="AgentTempDirectory" />
<Parameter xsi:type="StringParameter" name="SourceContent" value="" />
<Parameter xsi:type="StringParameter" name="VariableName" value="AgentTemp" />
</Statement>
<If description="">
<Condition name="TestFile">
<Parameter xsi:type="StringParameter" name="Path" value="#AgentTemp#\kav\kav_command_installkaspersky.lua" />
<Parameter xsi:type="EnumParameter" name="Condition" value="Exists" />
<Parameter xsi:type="StringParameter" name="Value" value="" />
</Condition>
<Then>
<Statement description="Exec Proc: KAV: Update License File / immediate" name="ExecuteScript" continueOnFail="false">
<Parameter xsi:type="StringParameter" name="ScriptID" value="343" />
<Parameter xsi:type="StringParameter" name="ScriptName" value="KAV: Update License File" />
<Parameter xsi:type="StringParameter" name="TimeDelay" value="" />
<Parameter xsi:type="EnumParameter" name="TimeUnit" value="Immediate" />
</Statement>
<Statement name="PauseScript" continueOnFail="false">
<Parameter xsi:type="IntegerParameter" name="Seconds" value="1" />
</Statement>
<Statement name="WriteScriptLogEntry" continueOnFail="false">
<Parameter xsi:type="StringParameter" name="Comment" value="Refresh KAV Key: License Key File Updated." />
</Statement>
</Then>
<Else>
<Statement name="WriteScriptLogEntry" continueOnFail="false">
<Parameter xsi:type="StringParameter" name="Comment" value="Refresh KAV Key: KAV is not installed." />
</Statement>
</Else>
</If>
</Body>
</Procedure>
</ScriptExport>
And Finally, I reimported the procedure from the XML file.
And voila... when I run the procedure on my laptop, the update.key file get copied under the #AgentTemp#\kav folder and I assume the DLL is run to import it in Kaspersky AV.
11:21:25 am 30-Apr-13 | Refresh KAV Key | FrancisG | |||
Script Summary: Success THEN | |||||
11:21:25 am 30-Apr-13 | Refresh KAV Key-0001 | FrancisG | |||
Script Summary: Success THEN | |||||
11:21:25 am 30-Apr-13 | Refresh KAV Key-0001 | FrancisG | |||
Refresh KAV Key: License Key File Updated. | |||||
11:21:24 am 30-Apr-13 | KAV: Update License File | FrancisG | |||
Script Summary: Success THEN | |||||
11:21:22 am 30-Apr-13 | Run Now - Refresh KAV Key | FrancisG |
Cheers
Francis Germain