Add computer to domain with batch file

I am building PC's from a ghost image, so when they first boot up, they have the same computer name, are on dhcp, and are not part of the domain.  I have figured out how to change the computer name and the ipaddress(thanks to people here), but how do I connect the pc to the domain.  This is my batch file so far:
 set /p YourIP=What is your IP address?
echo YourIP=%YourIP%



netsh interface ip set address local static %YourIP% 255.255.240.0 192.168.2.254 1

netsh interface ip set dns "Local Area Connection" static 192.168.0.19
netsh interface ip add dns "Local Area Connection" 192.168.0.25
netsh interface ip set wins "Local Area Connection" static 192.168.0.2
netsh interface ip add Wins "Local Area Connection" 192.168.0.6

Set /P Name="Enter the new computer name: "

:// Now, make the changes to the registry:
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ComputerName" /v ComputerName /t REG_SZ /d %Name% /f
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters" /v "NV Hostname" /t REG_SZ /d %Name% /f
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v ComputerName /t REG_SZ /d %Name% /f
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t REG_SZ /d %Name% /f

after it changes the name you are supposed to reboot.  Can you change the computername and add to the domain w/o restarting?  If I use this, and then use a netdom command I get the error message that the domain cannot be found
LVL 1
stamperbAsked:
Who is Participating?
 
gecko_au2003Connect With a Mentor Commented:
If you go to the bottom of this page :

http://www.scit.wlv.ac.uk/appdocs/chili-asp/html/vbscript_inputbox_function.htm

It gives you an example of an inputbox. I think it would be best if you tested out and took parts from the above script or scripts and altered it slightly to fit your needs and include an input box or boxes where you need them.
0
 
sirbountyCommented:
Why not use sysprep for this?
You can adjust your answer file to join to the domain during setup...
You could also put your IP batch file in there as well...
0
 
stamperbAuthor Commented:
I would rather have it prompt as it's working than make an answer file.  But how does it work?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
sirbountyCommented:
You take a base ghost image, include any non-personalized software and configuration.
Run sysprep against it - it'll remove the computer name and any other identifiers, then reboot.
Boot off a bootable floppy/usb - then drop down the new ghost image.
Each time you use it, you would be prompted to provide the new name for each system generated from that image (it basically starts you in the first Setup).

What I do is have a batch file run on first boot (Use the registry's RunOnce key) and display any messages, run additional software setup, etc...

http://support.microsoft.com/?id=302577
http://www.microsoft.com/windows2000/downloads/tools/sysprep/default.asp
0
 
stamperbAuthor Commented:
Do you have an example batch file?
0
 
sirbountyCommented:
Depends on what you want to do.
I use sysprep primarily for creating servers, but our workstation group uses it in their area as well.
If all you're wanting to do is display the acquired IP address, then I'd suggest a process like...

1) Create a source image - load the OS and all updates, applications, etc
2) Prepare the image - (to complete the above task)
  a) Create a batch file called runonce.cmd inside of %systemroot%\temp
      -@for /f "tokens=15" %%a in ('ipconfig^|find "IP A"') do net send %computername% Your IP address is %%a
  b) Create the 'cleanup' for the batch file, if desired
        echo del %systemroot%\temp\*.* /y > %systemroot%\temp\cleanup.bat
        reg add hklm\software\microsoft\windows\currentversion\runonce\cleanup.bat
3) Run sysprep
   a) start sysprep.exe -mini -reseal -reboot
4) boot off a floppy/usb
5) create the image using ghost -auto

In my batch file, I also generate a "Welcome to Windows - the following items are now installed" html file that is displayed on first boot as well - you can really get creative with it if you want..

You can have it log in using the administrator without prompting for x number of times after it's created.
If you want to join it to the domain, there's a [Identification] heading wher eyou would put that information inside your sysprep.inf file...you have to specify the credentials to use in that section as well...
0
 
gecko_au2003Commented:
With regards to restarting you could end the explorer.exe process and restart it via the task manager manually. I havent done any batch scripts or w/e you want to call them at all so I wouldnt have a clue how to do it via batch but I am fairly certain egl1044 has done it using WMI in a vbscript to end the explorer process and restart it so that it has the same effect as a restart :)
0
 
gecko_au2003Commented:
If you go here :

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21543314.html

Egl1044 has an example in visual basic 6 which can be easily converted to vbscript, if you would like me to I can convert it ( port it to vbscript )
0
 
sirbountyCommented:
You could easily use

tskill

to end explorer process (or pskill if not xp/2k3)
and then simply

start explorer.exe
0
 
gecko_au2003Commented:
Good suggestion sirbounty, I totally forgot about www.sysinternals.com lol :P Been a long day :-S.
0
 
stamperbAuthor Commented:
gecko, would you be able to change that into a vbscript for me.  I have tried just killing explorer and restarting it, but in my computer it still asks for a reboot.  When you change it to vbs, could you add my existing stuff from above, too??
0
 
gecko_au2003Commented:
If you could explain in plain english what you want it to do exactly and I will put together a one :)
0
 
stamperbAuthor Commented:
The first part of my batch file is asking me what I want the ip address to be.  When I put in the ip address, the batch file sets the ip address(that I entered), dns, and wins. The DNS, WINS, Subnet Mask and Default Gateway do not change at all.   The second part of the batch file are registry edits to change the computer name to what I specify. Before I can add the computer to the domain I have to restart first.   Now all I need it to do is to add it to the Domain without restarting and not have to restart and then add it to the domain manually.

So in plain english.>>>
I want a program that will ask me:  What is the ip address?
                                                    What is the hostname?
Then it will take the ipaddress that I tell it, add the ip, the default gateway, subnet mask, DNS, and WINS.
Then, it will change the computer name to what I tell it.
Then, add the computer to the domain.  
     All of this in one easy step, without restarting.
0
 
gecko_au2003Commented:
the part I dont get is about this :

"The DNS, WINS, Subnet Mask and Default Gateway do not change at all"

If they dont change why did you mention them or what do you want done with them, do you want msg boxes that let you know what they are or what ?
0
 
gecko_au2003Commented:
Also this will take me some time because I have to figure out how to do some of it, so if another expert can post a solution before I can thats fair enough :)
0
 
gecko_au2003Commented:
ok here :

http://www.microsoft.com/technet/scriptcenter/topics/networking/04_atnc_ipadd.mspx

That has lots of examples in scripting. I will be altering them to fit your needs, but basically instead of assigning an ip address hard coded you basically use an inputbox in vbscript to get it to prompt you for the ip address.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.