我正在尝试使用 WMI 和 System.Management 库将以下代码转换为 C#。谁能指出我正确的方向或提供一些帮助。
var IMPORT_CHILDREN = 0; // Recursively imports the subkeys of the specified key.
var IMPORT_INHERITED = 1; // Imports the inherited properties of the keys.
var IMPORT_NODE_ONLY = 2; // Does not import subkeys from the specified file.
var IMPORT_MERGE = 4; // Merges the imported keys into the existing configuration instead of completely replacing what is there.
var strPassword = "ExportingPassw0rd";
var strFilePath = "C:\\exported.xml";
var strSourceMetabasePath = "/lm/logging/custom logging"; // As represented in the metabase.xml file.
var strDestinationMetabasePath = "/lm/logging/custom logging"; // Can be different from the source.
var intFlags = IMPORT_NODE_ONLY | IMPORT_INHERITED; // Import only the node with inherited properties.
// Make connections to WMI, to the IIS namespace on MyMachine, and to the IIsComputer object.
var locatorObj = new ActiveXObject("WbemScripting.SWbemLocator");
var providerObj = locatorObj.ConnectServer("MyMachine", "root/MicrosoftIISv2");
var computerObj = providerObj.get("IIsComputer='LM'");
// Call export method from the computer object.
computerObj.Import(strPassword, strFilePath, strSourceMetabasePath, strDestinationMetabasePath, intFlags);
// Print results.
WScript.Echo("Imported the node in " + strFilePath + " to " + strDestinationMetabasePath);