WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

TCPIP and IP Address

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Change a Remote IP Address

Keywords: 	  IP address

Question:

How do I change a remote IP address?

Answer:

Here is the code I use to locate and SET the IP address of an NT workstation:
; Locate active adapter
;
svRegKey="Software\Microsoft\Windows NT\CurrentVersion\NetworkCards"
regKey=RegOpenKey(@RegMachine,svRegKey)

; How many are there?

NxtAdapter=RegQueryKey(regKey,0)
If NxtAdapter == "" then
Message("Error","No network adapters installed")
Exit
Endif

NetAdapter=RegQueryValue(regKey,"%NxtAdapter%\[ServiceName]")
NetTitle=RegQueryValue(Regkey,"%NxtAdapter%\[Title]")
Ok=RegCloseKey(RegKey)


; HKLM\System\CurrentControlSet\Services\adapter_name\Parameters\TCPIP

svRegKey="System\CurrentControlSet\Services\%NetAdapter%"
RegKey=RegOpenKey(@RegMachine,svRegKey)

Ok=RegSetMulSz(RegKey,"Parameters\tcpip\[IPAddress]",IpAddress," ")
Ok=RegSetMulSz(RegKey,"Parameters\tcpip\[DefaultGateway]",IPRouter," ")
Ok=RegSetMulSz(RegKey,"Parameters\tcpip\[SubnetMask]",IPMask," ")

OK=RegCloseKey(RegKey)
Return

And here is some IP code that allows one to change the IP remotely. Opening keys remotely can get a little tricky but the following article also helps (W13714)
AddExtender("WWWNT34I.DLL")
IntControl(49, 1, 0, 0, 0)
IntControl(4, 0,0,0,0)

cr=Num2Char(13) ; 13 is a carriage-return
lf=Num2Char(10) ; 10 is a line feed
crlf=StrCat(cr,lf)

:changeIP
servers = wntServerList("","NAR",4096)
remoteMachine=AskItemList("Windows NT Workstations or Servers",servers,@tab,@sorted,@single)
remoteMachine2=StrSub (remoteMachine, 3, 14)
newIP=AskLine ("Net Admin", "Enter the new IP address", "172.16.")
regRemoteMachine=RegConnect("%remotemachine%", @REGMACHINE)
key=RegOpenkey(regRemoteMachine, "Software\Microsoft\Windows NT\CurrentVersion\NetworkCards")
NxtAdapter=RegQueryKey(key,0)
NetAdapter=RegQueryValue(Key,"%NxtAdapter%\[ServiceName]")
NetTitle=RegQueryValue(Key,"%NxtAdapter%\[Title]")
RegCloseKey(Key)
svcKey=RegOpenKey(regRemoteMachine, "System\CurrentControlSet\Services\%NetAdapter%")
RegSetMulSz(svcKey,"Parameters\tcpip\[IPAddress]",newIp," ")
RegSetMulSz(svcKey,"Parameters\tcpip\[DefaultGateway]","172.16.20.1"," ")
RegSetMulSz(svcKey,"Parameters\tcpip\[SubnetMask]","255.255.0.0"," ")
RegSetDword(svcKey,"Parameters\tcpip\[EnableDHCP]","0")
RegCloseKey(svcKey)
RegCloseKey(regRemoteMachine)
Message("INFO", "Registry successfully modified on %remoteMachine2%.%crlf%The machine will need to be rebooted.") 


Article ID:   W14306
Filename:   How to Change a Remote IP Address.txt
File Created: 2001:03:01:12:16:38
Last Updated: 2001:03:01:12:16:38