Programming uses WMI control connection properties

zhaozj2021-02-16  42

Using system.management;

Namespace arli.commonprj {public class change {

///

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

///

/////// /// 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 /// Corresponding subnet mask list public void channelo (string [] ipaddr, string [] subnetMask) {Forech (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 /// gateway interface hop number list public void channelo (String [] ipaddr, string [] (! ManagementObject mo in moc) {if ((bool) subnetMask, string [] gateways, string [] gatewayCostMetric) {foreach 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 list /// Gateway list /// Gateway interface hop number list /// DNS server list public void changeTo (string [] ipAddr, string [] subnetMask, string [] gateways, string [] gatewayCostMetric, string [] dnsServer) {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 ( "Setgateway"); iobj ["defaultgateway"] = Gateways; IOBJ ["GatewayCostMetric"] = GatewayCostMeTric; OOBJ = Mo.invokeMethod ("setgateways", IObj, null;

Iobj = mtMethodparameters ("setDnsserversearchOrder"); IOBJ ["DNSSERVERSEARCHORDER"] = DNSSERVER; OOBJ = Mo.invokeMethod ("setDnsserversearchOrder", IObj, null);}}

///

Control connection so that it uses DHCP public void enabledhcp () {i (! (bool) Mo ["iPenabled"]) Continue;

IF (! "" "DHCPENABLED"]) {iobj = mtMethodParameters ("enabledhcp"); OOBJ = Mo.invokeMethod ("enabledHCP", IOBJ, NULL);}}}}}

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

New Post(0)