c# - Change remote IP address programmatically using WMI -


i writing application change ip addresses of local , remote machines using wmi. code changes gateway , dns of remote machine , same code (in different class , minus management scope part) changes of data (the 2 ips, gateway, dns) locally. problem doesn't change remote ip address. please can advise have looked everywhere answer?

i have tested on windows 7 , xp no firewalls , .net 4 installed on remote machines

class remoteipchange { public string settillip(string ipaddress1, string ipaddress2, string subnetmask, string gateway) { connectionoptions connection = new connectionoptions(); connection.username = "username"; connection.password = "password"; connection.authority = "ntlmdomain:domain"; managementscope scope = new managementscope( "\\\\"+ipaddress1+"\\root\\cimv2", connection); scope.connect(); objectgetoptions o = new objectgetoptions(); managementpath p = new managementpath("win32_networkadapterconfiguration"); managementclass objmc = new managementclass(scope,p,o); managementobjectcollection objmoc = objmc.getinstances(); foreach (managementobject objmo in objmoc) { if (!(bool)objmo["ipenabled"]) continue; try { managementbaseobject objnewip = null; managementbaseobject objsetip = null; managementbaseobject objnewgate = null; managementbaseobject objnewdns = null; objnewip = objmo.getmethodparameters("enablestatic"); objnewgate = objmo.getmethodparameters("setgateways"); objnewdns = objmo.getmethodparameters("setdnsserversearchorder"); //set defaultgateway objnewgate["defaultipgateway"] = new string[] { gateway }; objnewgate["gatewaycostmetric"] = new int[] { 1 }; //set ipaddress , subnet mask objnewip["ipaddress"] = new string[] { ipaddress1, ipaddress2 }; objnewip["subnetmask"] = new string[] { subnetmask, subnetmask }; //set dns servers objnewdns["dnsserversearchorder"] = new string[] {gateway }; //invoke changes objsetip = objmo.invokemethod("enablestatic", objnewip, null); objsetip = objmo.invokemethod("setgateways", objnewgate, null); objsetip = objmo.invokemethod("setdnsserversearchorder", objnewdns, null); return ("updated ipaddress " + ipaddress + ", \nsubnetmask " + subnetmask + " \nand default gateway " + gateway + "!"); } catch (exception ex) { return ("unable set ip : " + ex.message); } } return "code has not run"; } } 

i check returnvalue invokemethod on enablestatic. pretty sure passing in null subnet problem. provide valid array of subnets match ip addresses instead of null.


Comments

Popular posts from this blog

JQuery Autocomplete without using label, value, id -

c++ - Accessing inactive union member and undefined behavior? -

JAVA - what is the difference between void and boolean methods? -