1.

Solve : netsh command static ip assign?

Answer»

Hi Iam trying with this and cant make it to work??
------
SET /P IP= IPADRESS:
SET /P MASK= SUBNET:
SET /P GW= GATEWAY:
NETSH interface ip set address "Local Area Connection" static %IP% %MASK% %GW%
-----
Why??
reg/spesse :-/What values are entered for ipaddress, subnet, and gateway? Are they valid? What error messages did you get? This is the kind of information we need to troubleshoot problems...we shouldn't have to drag it out of you.

You can get full details from netsh interface ip set address /?

Good luck. 8-)Sorry... I got this
The syntax supplied for this command is not valid. Check help for the correct sy
ntax.

and I typing like this
IPADRESS? 192.168.32.10
SubNet? 255.255.255.0
Gateway? 192.18.32.1

And the syntax is OK I think??? SET /P IP IPADRESS? %IP% ??
As in my SCRIPT???The set statements seem to be fine. I found this help for the netsh command, which is where I suspect the problem is:

Quote

Remarks: Used to change the IP address configuration mode from either DHCP to
static mode or static mode to DHCP. Adds IP addresses on an
interface with static IP address or adds default gateways.

Examples:

set address name="Local Area Connection" source=dhcp
set address local static 10.0.0.9 255.0.0.0 10.0.0.1 1
Source: 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


Discussion

No Comment Found