Click here to Skip to main content
15,877,915 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
We use Kaspersky Security Center to manage AV on all our domain computers. I was looking for an external way to move computers to different groups and change the comments we give them in the Kaspersky Security Center. Kaspersky gave me some links to check out but I have no idea where to start on this. I was looking to code this in a VB.Net Windows Form Application.

Link1: https://support.kaspersky.com/9291
Link2: https://support.kaspersky.com/2810

What I have tried:

below is the JScript i want to run with vb.net:

JavaScript
function AcquireAdServerProxy()
{    
    var oSrvConnectionProps = new ActiveXObject("klakaut.KlAkParams");
    oSrvConnectionProps.Add("Address", "localhost:13291");
    oSrvConnectionProps.Add("UseSSL", true);

    var oAdmServer = new ActiveXObject("klakaut.KlAkProxy");
    oAdmServer.Connect(oSrvConnectionProps);
    return oAdmServer;
};

function Update_Host_Comment(hostid,comment)
{
    var oHosts = new ActiveXObject("klakaut.KlAkHosts");
    oHosts.AdmServer = AcquireAdServerProxy();
    var strHostName = hostid;    //name of the host to change attributes
   //Fill container with attributes to change
    var oProps = new ActiveXObject("klakaut.KlAkParams");
    oProps.Item("KLHST_WKS_COMMENT") = comment;    //Change Comment
    oHosts.UpdateHost(strHostName, oProps);
};

function Update_Host_Group(hostid,groupid)
{
    var oHosts = new ActiveXObject("klakaut.KlAkHosts");
    oHosts.AdmServer = AcquireAdServerProxy();
    var strHostName = hostid;    //name of the host to change attributes
    //Fill container with attributes to change
    var oProps = new ActiveXObject("klakaut.KlAkParams");
    oProps.Item("KLHST_WKS_GROUPID") = groupid;    //Change group
    oHosts.UpdateHost(strHostName, oProps);
};

//Calling Functions
Update_Host_Comment("SomeHostID","Some Comment Text");
Update_Host_Group("SomeHostID","Some GroupID");
Posted
Updated 4-Apr-23 3:56am

1 solution

Hi.

I just tried to do a syntactical conversion "out of my Memory"... :)

In VB You don´t end the command with a Semicolon, just by a NewLine (VbCrLf).
In VB 'var' is 'Dim', and its Syntax...
And the Functions should return something, thats why you set at the FunctionHeader not only Parameters, also a Return-Type (TypeOf BlaBliBlup)
-> As SomethingToReturn <- If You return a Printf/String you should use 'As String' to set the Type ouf the Return Value.

Howto use the ActiveX I forgot, but basicaly you do Referencing, then storeing into a Variable, and consume the ActiveX Instance.
Performe only on a small numbers of the ActiveX Instance(s).
Alot of Performance and Errros with ActiveX come from Creating always a new ActieX Instance inside Functions/Subs, and then You have to handle that...
Example: If you use only one PDF-ActiveX Instance, You don´t consume too much of Memory if yOu are using the same Document!

Subs in VB are "Functions with no Return Type (Void)".


VB
Function AcquireAdServerProxy() As SomethingToReturn
    
    Dim oSrvConnectionProps = New ActiveXObject("klakaut.KlAkParams")
    oSrvConnectionProps.Add("Address", "localhost:13291")
    oSrvConnectionProps.Add("UseSSL", true)

    Dim oAdmServer = new ActiveXObject("klakaut.KlAkProxy")
    oAdmServer.Connect(oSrvConnectionProps)
    Return oAdmServer
End Function

Function Update_Host_Comment(hostid As Something,comment As Something) As SomethingToReturn

    Dim oHosts = new ActiveXObject("klakaut.KlAkHosts")
    oHosts.AdmServer = AcquireAdServerProxy()
    Dim strHostName = hostid     'name of the host to change attributes
    'Fill container with attributes to change
    Dim oProps = new ActiveXObject("klakaut.KlAkParams")
    oProps.Item("KLHST_WKS_COMMENT") = comment   'Change Comment
    oHosts.UpdateHost(strHostName, oProps)
    
    ' Nothing to return ???
End Function

Function Update_Host_Group(hostid,groupid)

    Dim oHosts = New ActiveXObject("klakaut.KlAkHosts")
    oHosts.AdmServer = AcquireAdServerProxy()
    var strHostName = hostid     'name of the host to change attributes
    'Fill container with attributes to change
    var oProps = New ActiveXObject("klakaut.KlAkParams")
    oProps.Item("KLHST_WKS_GROUPID") = groupid     'Change group
    oHosts.UpdateHost(strHostName, oProps)
    
    ' Nothing to return ???
End Function

//Calling Functions
Update_Host_Comment("SomeHostID","Some Comment Text")
Update_Host_Group("SomeHostID","Some GroupID")



Here is another Version of the "Update_Host_Comment".
Changed to a Sub, and Defined the Parametertypes as Integer (hostid) and String (comment).

VB
Sub Update_Host_Comment(hostid As Integer, comment As String)
    Dim oHosts = new ActiveXObject("klakaut.KlAkHosts")
    oHosts.AdmServer = AcquireAdServerProxy()
    Dim strHostName = hostid     'name of the host to change attributes
    'Fill container with attributes to change
    Dim oProps = new ActiveXObject("klakaut.KlAkParams")
    oProps.Item("KLHST_WKS_COMMENT") = comment   'Change Comment
    oHosts.UpdateHost(strHostName, oProps)
End Sub


Maybe this will help.

This is not Working Code.

Just to get an intro by your example, and I am not a VB Guru.

c.u. from sunny Hamburg
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900