ManagementScope无法通过库工作

时间:2015-04-09 16:07:40

标签: wmi

我有以下代码直接从控制台应用程序工作。如果我将代码放入新库中,它只会针对某些类型的DNS记录抛出异常,尽管它适用于其他类型:

以下工作正常:

ConnectionOptions connectionOptions = new ConnectionOptions();
connectionOptions.Impersonation = ImpersonationLevel.Impersonate;

ManagementScope managementScope = new ManagementScope(@"\\.\root\MicrosoftDNS", connectionOptions);         
managementScope.Connect();

if (managementScope.IsConnected)
{               
    Console.WriteLine("Connected.");
}

ManagementClass managementClass = new ManagementClass(existingManagementScope, new ManagementPath("MicrosoftDNS_MXType"), null);

ManagementBaseObject managementParams = managementClass.GetMethodParameters("CreateInstanceFromPropertyData");
managementParams["DnsServerName"] = "ns1.example.com";
managementParams["ContainerName"] = "example.com";
managementParams["OwnerName"] = "example.com";
managementParams["MailExchange"] = "mail.google.com.";
managementParams["Preference"] = 10;
managementParams["TTL"] = 90;

managementClass.InvokeMethod("CreateInstanceFromPropertyData", managementParams, null);

以下不起作用:

MyDNSCMD dnscmd = new MyDNSCMD();
dnscmd.AddMXResourceRecord(ref managementScope, "example.com", "mail.google.com", 15, 90);

以下作品:

MyDNSCMD dnscmd = new MyDNSCMD();
dnscmd.AddAResourceRecord(ref managementScope, "example.com", "mail", "192.168.0.88", 90);

0 个答案:

没有答案