Link to home
Start Free TrialLog in
Avatar of stamperb
stamperb

asked on

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
Avatar of sirbounty
sirbounty
Flag of United States of America image

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...
Avatar of stamperb
stamperb

ASKER

I would rather have it prompt as it's working than make an answer file.  But how does it work?
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
Do you have an example batch file?
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...
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 :)
If you go here :

https://www.experts-exchange.com/questions/21543314/how-to-show-hide-the-my-computer-icon-my-documents-icon-network-places-icon-on-the-desktop.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 )
You could easily use

tskill

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

start explorer.exe
Good suggestion sirbounty, I totally forgot about www.sysinternals.com lol :P Been a long day :-S.
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??
If you could explain in plain english what you want it to do exactly and I will put together a one :)
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.
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 ?
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 :)
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.
ASKER CERTIFIED SOLUTION
Avatar of Shane Russell
Shane Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial