【解決方法】jscript を VB.NET に変換する方法

プログラミングQA


Kaspersky Security Center を使用して、すべてのドメイン コンピューターで AV を管理しています。 コンピューターを別のグループに移動し、Kaspersky Security Center で与えるコメントを変更する外部の方法を探していました。 カスペルスキーはチェックアウトするためのリンクをいくつか提供してくれましたが、どこから始めればよいかわかりません。 これをVB.Net Windowsフォームアプリケーションでコーディングしようとしていました。

リンク 1: https://support.kaspersky.com/9291

リンク 2: https://support.kaspersky.com/2810

私が試したこと:

以下は、vb.net で実行したい JScript です。

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");

解決策 1

やあ。

「メモリ不足」の構文変換を試みました… 🙂

VB では、セミコロンでコマンドを終了せず、NewLine (VbCrLf) だけで終了します。
VB では ‘var’ は ‘Dim’ であり、その構文は…
そして、関数は何かを返す必要があります。そのため、FunctionHeader でパラメーターだけでなく、Return-Type (TypeOf BlaBliBlup) も設定します。
-> As SomethingToReturn <- Printf/String を返す場合は、'As String' を使用して戻り値のタイプを設定する必要があります。 ActiveXの使い方は忘れましたが、基本的には参照してから変数に格納し、ActiveXインスタンスを消費します。
少数の ActiveX インスタンスでのみ実行します。
ActiveX の多くのパフォーマンスとエラーは、Functions/Subs 内で常に新しい ActieX インスタンスを作成することから発生し、それを処理する必要があります…
例: PDF-ActiveX インスタンスを 1 つだけ使用する場合、同じドキュメントを使用していれば、メモリをあまり消費しません。

VB の Subs は「戻り値の型を持たない関数 (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")

「Update_Host_Comment」の別のバージョンを次に示します。
Sub に変更し、Parametertypes を Integer (hostid) および 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

多分これが役立つでしょう。

これは作業コードではありません。

あなたの例で紹介するだけで、私はVB Guruではありません。

日当たりの良いハンブルクの cu

解決策 2

関数validateTaxRef(refVal) {
var validTax = document.getElementById(“<%=hdValidTax.ClientID%>“);
有効な税金。値 = 0;
アラート (validTax.value);
if (refVal.length != 10) {
false を返します。
}

var checkDigit = parseInt(refVal.charAt(refVal.length – 1));
var 奇数 = “”;
var 偶数 = 0;
var oddResult = 0;
結果でした;
var start = 0;//常に 0,1,2,3,9 で開始する必要があります)
var start = parseInt(refVal.charAt(0));
//if (開始 == 0 || 開始 == 1 || 開始 == 2 || 開始 == 3 || 開始 == 9)
if (開始 == 0 || 開始 == 1 || 開始 == 2 || 開始 == 3) {
}
それ以外 {
false を返します。
}

for (var c = 1; c <= refVal.length; c++) {
もし (c % 2 != 0) {
奇数 += refVal.charAt(c – 1);
} それ以外 {
if (c == refVal.length) {
続く;
} それ以外 {
偶数 = (parseInt(偶数) + parseInt(refVal.charAt(c – 1)));
}
}
}
奇数 = (数 (奇数) * 2);
奇数 = 奇数.toString();
for (var r = 1; r <= odd.length; r++) {
oddResult = (parseInt(oddResult) + parseInt(odd.charAt(r – 1)));
}

結果 = (parseInt(偶数) + parseInt(奇数結果));
結果 = 結果.toString();

結果 = (10 – parseInt(result.charAt(result.length – 1)));
結果 = 結果.toString();

if (result.length > 1) {
結果 = 結果.charAt(結果.長さ – 1);
}

if (parseInt(result) != checkDigit) {
false を返します。
} それ以外 {
true を返します。
有効な税金。値 = 1;
}
}

コメント

タイトルとURLをコピーしました