Programming uses WMI control connection properties

xiaoxiao2021-03-06  138

Title Programming Using WMI Control Connection Properties Arli2003 (Original) Keyword Programming Using WMI Control Connection Properties, IP, DNS, Gateway, Gateway, WMI

using System; using System.Management; namespace ArLi.CommonPrj {public class ChangeIP {///

/// Build of ArLi 2003.6.3 /// public static readonly System.Version myVersion = new System. Version (1,1); private ManagementBaseObject iObj = null; private ManagementBaseObject oObj = null; private ManagementClass mc = new ManagementClass ( "Win32_NetworkAdapterConfiguration"); private readonly ManagementObjectCollection moc; /// /// Example: /// /// arli.commonprj.changeip o = new arli.commonprj.changeip (); /// String [] iplist = new string [] {"192.168.0.253", "192.168.0.250"}; // / String [] SUBNETLIST = new string [] "255.255.255.0", "255.255.255.0"}; /// o.changeto (iPlist, subnetList); /// /// Public change () {moc = mc.getinstances ();} /// Control connection /// IP address list /// Correspondence subnet mask list public void channelo (String [] ipaddr, string [] subnetmask {FOREACH ( ManagementObject Mo in moc) {if (! "" IPenabled "]) Continue; IOBJ = Mo.getMethodParameters (" enablestatic "); IOBJ [ipaddress"] = ipaddr; IOBJ ["SubnetMask"] = SubnetMask; OOBJ = Mo.invokeMethod ("EnableStatic", IObj, null;}} /// Control connection /// IP address list ////////// Corresponding subnet mask list /// gateway list /// <

param name = "gatewayCostMetric"> metric listing gateway interface public void ChangeTo (string [] ipAddr, string [] subnetMask, string [] gateways, string [] gatewayCostMetric) {foreach (ManagementObject mo in moc) {if (! (BOOL) MO ["iPenabled"]) Continue; IOBJ = Mo.getMethodParameters ("enablestatic"); IOBJ [ipaddress "] = ipaddr; IOBJ [" SubnetMask "] = SubnetMask; Oobj = Mo.invokeMethod (" EnableStatic ", iObj, null); iObj = mo.GetMethodParameters (" SetGateways "); iObj [" DefaultIPGateway "] = gateways; iObj [" gatewayCostMetric "] = gatewayCostMetric; oObj = mo.InvokeMethod (" SetGateways ", iObj, null );}} ///

Control connection /// IP address list /// corresponding subnet mask Listing /// Gateway list /// Gateway interface hop number list /// DNS server list public void channelo (String [] ipaddr, string [] subnetMask, string [] Gateways, String [] GatewayCostMetric, String [] DNSServer ) {IF (! (Boxenable) mo ["iPenabled"]) Continue; IOBJ = Mo.getMethodParameters ("enablestatic"); IOBJ [ipaddress "] = ipaddr; IOBJ [" SubnetMask " ] = subnetMask; oObj = mo.InvokeMethod ( "EnableStatic", iObj, null); iObj = mo.GetMethodParameters ( "SetGateways"); iObj [ "DefaultIPGateway"] = gateways; iObj [ "gatewayCostMetric"] = gatewayCostMetric;

转载请注明原文地址:https://www.9cbs.com/read-127346.html

New Post(0)