control tcp settings

R

Rene Sørensen

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("EnableStatic");
obj_gateway = management_object.GetMethodParameters("SetGateways");
obj_dns = management_object.GetMethodParameters("EnableDNS");
obj_wins = management_object.GetMethodParameters("SetWINSServer");

//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);
 
G

Guest

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

}
 
G

Guest

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

}
}
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top