[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Add computer to domain with batch file

Posted on 2005-09-29
16
Medium Priority
?
23,019 Views
Last Modified: 2011-08-18
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
0
Comment
Question by:stamperb
  • 8
  • 4
  • 4
16 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 14983132
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
 
LVL 1

Author Comment

by:stamperb
ID: 14983826
I would rather have it prompt as it's working than make an answer file.  But how does it work?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 14983896
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:stamperb
ID: 14984875
Do you have an example batch file?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 14985036
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 14985976
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 14986351
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 14986391
You could easily use

tskill

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

start explorer.exe
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 14986474
Good suggestion sirbounty, I totally forgot about www.sysinternals.com lol :P Been a long day :-S.
0
 
LVL 1

Author Comment

by:stamperb
ID: 14991845
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 14994255
If you could explain in plain english what you want it to do exactly and I will put together a one :)
0
 
LVL 1

Author Comment

by:stamperb
ID: 14994591
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 14995186
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 14995377
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 14995416
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
 
LVL 23

Accepted Solution

by:
gecko_au2003 earned 1500 total points
ID: 14995610
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Progress
Introduction to Processes

868 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