Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to change computer name and IP from a batch file

Posted on 2004-09-14
5
Medium Priority
?
786 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 300 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 200 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 60

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I don't know if many of you have made the great mistake of using the Cisco Thin Client model with the management software VXC. If you have then you are probably more then familiar with the incredibly clunky interface, the numerous work arounds, and …
Sometimes a user will call me frantically, explaining that something has gone wrong and they have tried everything (read - they have messed it up more and now need someone to clean up) and it still does no good, can I help them?!  Usually the standa…
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.

916 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