Solved

How to change computer name and IP from a batch file

Posted on 2004-09-14
5
760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 57

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Many people tend to confuse the function of a virus with the one of adware, this misunderstanding of the basic of what each software is and how it operates causes users and organizations to take the wrong security measures that would protect them ag…
Windows 7 does not have the best desktop search built in. This is something Windows 7 users have struggled with. You type something in, and your search results don’t always match what you are looking for, or it doesn’t actually work at all. There ar…
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.

734 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