By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,170 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,170 IT Pros & Developers. It's quick & easy.

control tcp settings

P: n/a
I'm createing a tool to managet ip addresses, this is a profile
manager. I can control ip and subnet, but i can't control dns and
wins. The error i get is "invalid method", the code im using is below
here. Can someone tell what im doing wrong?..

//create objects
ManagementBaseObject obj_ip = null;
ManagementBaseObject obj_gateway = null;
ManagementBaseObject obj_wins = null;
ManagementBaseObject obj_dns = null;
ManagementBaseObject obj_output = null;

// get method
obj_ip = management_object.GetMethodParameters("EnableStati c");
obj_gateway = management_object.GetMethodParameters("SetGateways ");
obj_dns = management_object.GetMethodParameters("EnableDNS") ;
obj_wins = management_object.GetMethodParameters("SetWINSServ er");

//Set DefaultGateway
obj_gateway["DefaultIPGateway"] = new string[] { gateway };
obj_gateway["GatewayCostMetric"] = new int[] { 1 };
//Set IPAddress and Subnet Mask
obj_ip["IPAddress"] = new string[] { ip_address };
obj_ip["SubnetMask"] = new string[] { subnet_mask };

// set wins server
obj_wins["WINSPrimaryServer"] = new string[] { wins };

//// set dns servers
obj_dns["DNSServerSearchOrder"] = new string[] { primary_dns,
secudary_dns };

obj_output = management_object.InvokeMethod("EnableStatic", obj_ip,
null);

obj_output = management_object.InvokeMethod("SetGateways",
obj_gateway, null);

obj_output = management_object.InvokeMethod("EnableDNS", obj_dns,
null);

obj_output = management_object.InvokeMethod("SetWINSServer", obj_wins,
null);
May 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
hi ho!

i got the same problem with WINS, but i can change the DNS serves like this:

public void setDNS(string NIC, string DNS)
{
ManagementClass objMC = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection objMOC = objMC.GetInstances();

foreach (ManagementObject objMO in objMOC)
{

if ((bool)objMO["ipEnabled"])
{
if (objMO["Caption"].Equals(NIC))
{
ManagementBaseObject newDNS =
objMO.GetMethodParameters("SetDNSServerSearchOrder ");
newDNS["DNSServerSearchOrder"] = DNS.Split(',');
ManagementBaseObject setDNS =
objMO.InvokeMethod("SetDNSServerSearchOrder", newDNS, null);
}
}
}

}
Aug 10 '06 #2

P: n/a
hi folks,

today i solve the problem to set the wins server using C# and WMI, i use the
following function to set primary and secondary WINS server... hope it's
useful for you!

greetz. nO_okY
public void setWINS(string NIC, string priWINS, string secWINS)
{
ManagementClass objMC = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection objMOC = objMC.GetInstances();

foreach (ManagementObject objMO in objMOC)
{

if ((bool)objMO["ipEnabled"])
{
if (objMO["Caption"].Equals(NIC))
{
ManagementBaseObject setWINS;
ManagementBaseObject wins =
objMO.GetMethodParameters("SetWINSServer");
wins.SetPropertyValue("WINSPrimaryServer", priWINS);
wins.SetPropertyValue("WINSSecondaryServer", secWINS);

setWINS = objMO.InvokeMethod("SetWINSServer", wins,
null);

}
}
}

}
Aug 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.