Solved

How to change computer name and IP from a batch file

Posted on 2004-09-14
5
756 Views
Last Modified: 2008-01-09
Anyone know how to change the computer name and IP from a batch file. If this is not directly possible is there some freeware utility which I can call from a batch file passing the new computer name and IP?
0
Comment
Question by:CharlesSHill
5 Comments
 
LVL 4

Accepted Solution

by:
Kaarthick earned 75 total points
ID: 12062042
Command to Change IP Address

netsh interface ip set address name="Local Area Connection" static 192.168.0.28 255.255.255.0 192.168.0.1 1
0
 
LVL 2

Assisted Solution

by:russhuntington
russhuntington earned 50 total points
ID: 12063072
If you have support tools installed, you can use: "NETDOM RENAME COMPUTER targetComputer /NewName:newName". With older Windows operating systems, you can use "hostname -s".
0
 
LVL 4

Expert Comment

by:Kaarthick
ID: 12063125
The following link gives you some information regarding NETDOM which was suggested by "russhuntington"

http://support.microsoft.com/default.aspx?scid=kb;en-us;298593&sd=tech
0
 

Expert Comment

by:roberm
ID: 12063204
Below is part of a Perl script ive done used to change both IP and machine name as part of an automated configuration script. It basically changes the registry directly. I you do not wish to use Perl then u can simply use a .reg file, incorporating the registry keys in the script below. The .reg file can then be launched from within your .bat file.

At the bottom half is an example of a  .reg file for your purpose simply replace the computer name, and IP address with the ones u wish to use.

Hope this helps.


==============================================

use Win32::Registry;

#######------Change computer name in registry------######


      $key='System\CurrentControlSet\Control\ComputerName\ComputerName';
      Win32::Registry::RegOpenKeyEx
            (&HKEY_LOCAL_MACHINE,$key,NULL,&KEY_ALL_ACCESS,$RegHandle);
      Win32::Registry::RegSetValueEx
            ($RegHandle, 'ComputerName', NULL, &REG_SZ, $computername);
      Win32::Registry::RegCloseKey($RegHandle);
      
      $key='System\CurrentControlSet\Services\Tcpip\Parameters';
      Win32::Registry::RegOpenKeyEx
            (&HKEY_LOCAL_MACHINE,$key,NULL,&KEY_ALL_ACCESS,$RegHandle);
      Win32::Registry::RegSetValueEx
            ($RegHandle, 'ComputerName',NULL, &REG_SZ, $computername);
      Win32::Registry::RegCloseKey($RegHandle);
      
      $key='System\CurrentControlSet\Services\Tcpip\Parameters';
      Win32::Registry::RegOpenKeyEx
            (&HKEY_LOCAL_MACHINE,$key,NULL,&KEY_ALL_ACCESS,$RegHandle);
      Win32::Registry::RegSetValueEx
            ($RegHandle, 'Hostname',NULL, &REG_SZ, $computername);
      Win32::Registry::RegCloseKey($RegHandle);


######------Change the IP Address in the registry------######


      $key='System\CurrentControlSet\Services\El90x1\Parameters\Tcpip';
      Win32::Registry::RegOpenKeyEx
            (&HKEY_LOCAL_MACHINE,$key,NULL,&KEY_ALL_ACCESS,$RegHandle);
      Win32::Registry::RegSetValueEx
            ($RegHandle, 'IPAddress',NULL, &REG_MULTI_SZ, $finalip);
      Win32::Registry::RegCloseKey($RegHandle);
      
      $key='System\ControlSet001\Services\El90x1\Parameters\Tcpip';
      Win32::Registry::RegOpenKeyEx
            (&HKEY_LOCAL_MACHINE,$key,NULL,&KEY_ALL_ACCESS,$RegHandle);
      Win32::Registry::RegSetValueEx
            ($RegHandle, 'IPAddress',NULL, &REG_MULTI_SZ, $finalip);
      Win32::Registry::RegCloseKey($RegHandle);

      $key='System\ControlSet003\Services\El90x1\Parameters\Tcpip';
      Win32::Registry::RegOpenKeyEx
            (&HKEY_LOCAL_MACHINE,$key,NULL,&KEY_ALL_ACCESS,$RegHandle);
      Win32::Registry::RegSetValueEx
            ($RegHandle, 'IPAddress',NULL, &REG_MULTI_SZ, $finalip);
      Win32::Registry::RegCloseKey($RegHandle);


=================================================================
.reg example
=================================================================

REGEDIT4

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName]
"ComputerName"="bobs_computer"

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters]
"ComputerName"="bobs_computer"

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters]
"Hostname"="bobs_computer"

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\El90x1\Parameters\Tcpip]
"IPAddress"="168.192.1.1"

[HKEY_LOCAL_MACHINE\System\ControlSet001\Services\El90x1\Parameters\Tcpip]
"IPAddress"="168.192.1.1"

[HKEY_LOCAL_MACHINE\System\ControlSet003\Services\El90x1\Parameters\Tcpip]
"IPAddress"="168.192.1.1"






0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 12064371
Changing the IP address ok.

But with the machine name remmber that for the name to become active you need to restart the compuater AND if the computer is a member of a domain the domain account for the computer has to be recreated in order for the machine to be able to logon to the domain.

There are API's to do this but it is fairly involved if you want to do the reboot and the creation of the domain account. If the domain account is not necessary - then much easier.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

#Citrix #POC #XenDesktop #vCenter #VMware #ESX
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now