Solved

How to change computer name and IP from a batch file

Posted on 2004-09-14
5
755 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 51

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction How to create multiboot configuration with XP\Vista and Windows 7 on it? And most important question - how to do this correctly so not to have any kind of nightmares we get when system gets screwed? First of all one should realize t…
As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

9 Experts available now in Live!

Get 1:1 Help Now