Batch File To automate TFTP/PXE Setup

Hello World,

This is the batch file sample that can be used to automate the setup of a TFTP/PXE server on a windows 2003 box.  Some limitations apply on this “basic” batch file. The limitations are the following :

  • batch file has been tested on windows 2003. batch file as is will not work on Windows 2008.
  • DHCP service should be installed before the script run
  • You need to modify the script in order to reflect your environment
  • Use the script at your own risk ! I’ll not be held responsible for any damage you might experience. The script is provided to you “AS IS”

Copy this text to notepad and save it as batch file (.bat extension)

@echo off
Rem Basic batch file to quickly configure a Windows 2003 box with TFTP service capabilities

REM *****************************************************************************
REM * MODIFY AS REQUIRED
REM *
REM * BEFORE RUNNING THE SCRIPT, INSTALL DHCP SERVICE IF NOT ALREADY DONE !!
REM * SCRIPTING RUNNING ONLY ON WINDOWS 2003 BOX (New Version in Progress
REM *
REM * ***************************************************************************

SET STRDIR=C:\TFTPROOT
SET DHCPSCOPENAME=PXE
SET DHCPSCOPEDESC=”DHCP SCOPE PXE CLIENTS”
SET DHCPIPSCOPE=192.168.1.0
SET DHCPIPSUbnet=255.255.255.0
SET DHCPSCOPERANGE=192.168.1.200 192.168.1.250
SET TFTPIP=192.168.1.23
SET PXEBOOTFILENAME=pxeboot.n12

cls
echo.

REM DO NOT REMOVE THIS SECTION
Echo ——————————————————————–
Echo – Compiled by Griffon – 2010 – http://www.C-nergy.be/blog
echo – Script to Quickly install TFTP/PXE Capabilities for Windows 2003
echo – Version 0.1
echo ——————————————————————–
echo.
echo.
echo.

Echo ——————————————–
Echo –
echo – STEP 1 : Copying File TFTP.EXE
echo –
echo ——————————————–

copy %systemroot%\system32\dllCache\tftpd.exe %systemroot%\system32\

Echo ——————————————–
Echo –
echo – STEP 2 : INSTALL AS A SERVICE
echo –
echo ——————————————–

sc create TFTPD binpath= c:\windows\system32\tftpd.exe start= auto
net start TFTPD

Echo ————————————————————-
Echo –
echo – STEP 3 : TFTP ROOT DIRECTORY AND REGISTRY SETTINGS
echo –
echo ————————————————————–

MKDIR %STRDIR%
reg Add HKLM\SYSTEM\CurrentControlSet\Services\TFTPD\Parameters /v Directory /t REG_SZ /d %STRDIR%

Echo ——————————————–
Echo –
echo – STEP 4 : CONFIGURE YOUR DHCP SERVER
echo –
echo ——————————————–

Echo IS DHCP SERVICE INSTALLED ? Press Y to Proceed, Press Ctrl+C to Abort !”
pause

netsh dhcp server add scope %DHCPIPSCOPE% %DHCPIPSUbnet% %DHCPSCOPENAME% %DHCPSCOPEDESC%
netsh dhcp server scope %DHCPIPSCOPE% add iprange %DHCPSCOPERANGE%
netsh dhcp server scope %DHCPIPSCOPE% set optionvalue 066 String %TFTPIP%
netsh dhcp server scope %DHCPIPSCOPE% set optionvalue 067 String %PXEBOOTFILENAME%
net stop DHCP
net start DHCP
netsh dhcp server scope %DHCPIPSCOPE% set optionvalue 043 Binary 010400000000ff
netsh dhcp server add optiondef 60 PXEClient String 0 Comment=PXE Support
netsh dhcp server set optionvalue 60 String PXEClient

Echo ——————————————–
Echo –
echo – CONFIGURATION COMPLETED !!
echo –
echo ——————————————–
echo.
echo.
echo Populate your TFTP ROOT Directory with your PXE bootable files
echo.
echo.

pause

That is for this post

Note: A new version of this script is being developed !  You will get a nice GUI to setup your TFTP/PXE infrastructure.

See ya

One thought on “Batch File To automate TFTP/PXE Setup

Leave a Reply