我们使用 Kaspersky Security Center 来管理我们所有域计算机上的 AV。我一直在寻找一种外部方法来将计算机移动到不同的组并更改我们在 Kaspersky Security Center 中给他们的评论。卡巴斯基给了我一些检查链接,但我不知道从哪里开始。我希望在 VB.Net Windows 窗体应用程序中对此进行编码。
我的问题是如何转换或使下面的 jscript 在 VB.net Windows 窗体中工作。我将有一个加载了 Kaspersky 主机 ID、评论和 GroupID 的 sql 表。每天一次,我想遍历该 sql 表,只更新需要对其评论或组进行更改的计算机。(我已经写过的sql部分)
这是我的目标:
Dim reader3 As SqlDataReader
Dim strconnection3 As String
strconnection3 = data_source_all 'defined globally
Dim SqlConnection3 As New SqlConnection(strconnection3)
Dim cmd3 As New SqlCommand
cmd3.CommandText = "SELECT kaspersky_hostid, kaspersky_comment, pc_info_comment, kaspersky_groupid FROM pc_info where (pc_status = 'active')"
cmd3.CommandType = CommandType.Text
cmd3.Connection = SqlConnection3
SqlConnection3.Open()
reader3 = cmd3.ExecuteReader()
If reader3.HasRows Then
While reader3.Read()
If reader3(1).ToString = reader3(2).ToString Then
Else
Update_Host_Comment(reader3(0).ToString,reader3(2).ToString)
End If
End While
SqlConnection3.Close()
SqlConnection3.Dispose()
cmd3.Dispose()
Else
End If
Public Sub Update_Host_Comment(ByVal hostid As String, ByVal comment As String)
'Converted JScript
'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);
End Sub
链接1: https://support.kaspersky.com/9291 链接2: https : //support.kaspersky.com/2810
下面是我想用 vb.net 运行的 JScript:
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");
06/04/18 编辑:这是我尝试过的代码:
Public Function AcquireAdServerProxy()
Try
Dim oSrvConnectionProps = CreateObject("klakaut.KlAkParams")
oSrvConnectionProps.Add("Address", "localhost:13291")
oSrvConnectionProps.Add("UseSSL", True)
Dim oAdmServer = CreateObject("klakaut.KlAkProxy")
oAdmServer.Connect(oSrvConnectionProps)
Return oAdmServer
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
Public Function Update_Host_Comment(ByVal hostid As String, ByVal comment As String) As Boolean
Try
Dim ohosts = CreateObject("klakaut.KlAkHosts")
ohosts.AdmServer = AcquireAdServerProxy()
Dim strHostName = hostid
'Fill container with attributes to change
Dim oProps = CreateObject("klakaut.KlAkParams")
oProps.Item("KLHST_WKS_COMMENT") = comment
ohosts.UpdateHost(strHostName, oProps)
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
Public Function Update_Host_Group(ByVal hostid As String, ByVal groupid As Integer) As Boolean
Try
Dim ohosts = CreateObject("klakaut.KlAkHosts")
ohosts.AdmServer = AcquireAdServerProxy()
Dim strHostName = hostid
'Fill container with attributes to change
Dim oProps = CreateObject("klakaut.KlAkParams")
oProps.Item("KLHST_WKS_GROUPID") = groupid
ohosts.UpdateHost(strHostName, oProps)
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label4.Text = "Processing ..."
Label4.Update()
Try
If TextBox1.Text <> Nothing Then
If TextBox2.Text <> Nothing Then
If Update_Host_Comment(TextBox1.Text, TextBox2.Text.ToUpper) Then
Label4.Text = "Comment Updated"
Label4.Update()
Else
Label4.Text = "Comment Update Error"
Label4.Update()
End If
Else
End If
If TextBox3.Text <> Nothing And IsNumeric(TextBox3.Text) Then
If Update_Host_Group(TextBox1.Text, TextBox3.Text) Then
Label4.Text = Label4.Text & " / Group Updated"
Label4.Update()
Else
Label4.Text = Label4.Text & " / Group Update Error"
Label4.Update()
End If
Else
End If
End If
Catch ex As Exception
Label4.Text = "Error"
Label4.Update()
End Try
End Sub
End Class
这是我运行它时遇到的错误:
System.Runtime.InteropServices.COMException (0xE0FF04FD):连接到http://localhost:13291时出现传输级错误:无法解析 Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object [] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] kaspersky_api.Form1.AcquireAdServerProxy() 中的 TypeArguments、Boolean[] CopyBack、Boolean IgnoreReturn)