| 1. |
Solve : netsh command static ip assign? |
|
Answer» Hi Iam trying with this and cant make it to work?? Remarks: Used to change the IP address configuration mode from either DHCP toSource: Microsoft Help Command Good luck. 8-)Tanx I solved it by my self.. The right syntax and execute command should look like this ********* SET /P IP= IPADRESS? SET /P MASK= SUBNET? SET /p GW= GATEWAY? netsh interface ip set address name="Local Area Connection" source=static %IP% %MASK% %GW% 1 ********* obvious this only works if you don't have changed your Nic name... To put it back to DHCP **** netsh interface ip set address "Local Area Connection" dhcp **** And for vbs like this. *********** strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE AND index=9") IP = InputBox("Type In New IP Adress eg. 10.11.12.13", "", "Type Here") SUBN = InputBox("Type In New Sub Net Mask eg. 255.255.255.0", "", "Type Here") GW = InputBox("Type In New Gateway eg. 10.11.12.1", "", "Type Here") DNS = InputBox("Type In New DNS eg. 10.11.12.3", "", "Type Here") strIPAddress = Array(IP) strSubnetMask = Array(SUBN) strGateway = Array(GW) strGatewayMetric = Array(1) For Each objNetAdapter in colNetAdapters errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) If errEnable = 0 Then WScript.Echo "The IP address has been changed." Else WScript.Echo "The IP address could not be changed." END If Next *************** But I have trouble to make it generic "index 9" that is my Nic on this computer. I am no good @ vbs but i am getting there, i will try to list all my Nic and make a choice eg. 1 =lan ,2 =Wifi, 3=Blue tooth etc... and den run the script. I will post the solution if I can make it to work.. :-/ reg/spesseOne nice things about functions is that they return a value which you can use to your advantage: Code: [Select]strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE AND index=" [highlight]& GetIndex()[/highlight]) IP = InputBox("Type In New IP Adress eg. 10.11.12.13", "", "Type Here") SUBN = InputBox("Type In New Sub Net Mask eg. 255.255.255.0", "", "Type Here") GW = InputBox("Type In New Gateway eg. 10.11.12.1", "", "Type Here") DNS = InputBox("Type In New DNS eg. 10.11.12.3", "", "Type Here") strIPAddress = Array(IP) strSubnetMask = Array(SUBN) strGateway = Array(GW) strGatewayMetric = Array(1) For Each objNetAdapter in colNetAdapters errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) If errEnable = 0 Then WScript.Echo "The IP address has been changed." Else WScript.Echo "The IP address could not be changed." End If Next Function getIndex() Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") cnt = 0 For Each Adapter In colNetAdapters cnt = cnt + 1 strMenu = strMenu & cnt & ". " & Adapter.description & vbCrLf Next getIndex = InputBox(strMenu, "Choose The Adapter") If CINT(getIndex) > cnt Then getIndex() End Function This should prompt the user by giving a menu of adapters from which the user can choose by number. Nice script by the way. Note: You might want to do more error trapping so the user input is not too ridiculous. yeah |
|