[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.axapta.programming

Edit DNS with WMI and C#

napilut

11/30/2005 8:17:00 AM

I'm creating an application to edit my TCP/IP configuration loading a xml
configuration file. I'm using WMi and C#, using, for example, to edit my ip,
gateway and subnetmask, this C# code:

ManagementBaseObject objNewIP = null;
ManagementBaseObject objSetIP = null;
ManagementBaseObject objNewGate = null;
objNewIP = objMO.GetMethodParameters("EnableStatic");
objNewGate = objMO.GetMethodParameters("SetGateways");

objNewGate["DefaultIPGateway"] = new string[] {config.Gateway};
objNewGate["GatewayCostMetric"] = new int[] {1};
objNewIP["IPAddress"] = new string[] { config.IPAddress };
objNewIP["SubnetMask"] = new string[] { config.SubnetMask };
objSetIP = objMO.InvokeMethod("EnableStatic",objNewIP,null);
objSetIP = objMO.InvokeMethod("SetGateways",objNewGate,null);


But, when I try to edit my DNS's servers with this code:

ManagementBaseObject objNewDns = null;
ManagementBaseObject objSetDns = null;

objNewDns = objMO.GetMethodParameters("EnableDNS");

objNewDns["DNSHostName"] = null;
objNewDns["DNSDomain"] = null;
objNewDns["DNSServerSearchOrder"] = new string[] { config.Dns1, config.Dns2 };
objNewDns["DNSDomainSuffixSearchOrder"] = null;
objSetDns = objMO.InvokeMethod("EnableDNS",objNewDns, null);

The code fails. I've found in an internet forum that it fails because the
"EnableDNS" method is a static method. The forum's reply say "ok!, thanks",
but not the solution.

How can I invoke this static method or how can I edit my DNS's servers using
C#???

Thank you!