I was given the task to rewrite the login script for a company, they had 4 sites and about 20 login scripts for various purposes.
So I wrote a general one which took care of all the general stuff.
You may look at my earlier post about an inventory script, because this script will use that one.
:: REQUIREMENTS :: DOWNLOAD con2prt.exe from google :: Put con2prt.exe in \netlogon of all your DC's :: EDIT LINE 16-19, 22-25, 50 :: DEFINE GLOBAL VARS AND CONFIGS. @echo off cls mode 60,20 color 3e set pause=0 set debug=0 title Login Script - Company Name :: Define name of your global catalog/domain controller set dc1=site1pdc set dc2=site2pdc set dc3=site3pdc set dc4=site4pdc :: DEFINE DEFAULT GATEWAY OF EACH LOCATION set site1=10.0.1.254 set site2=10.0.2.254 set site3=10.0.5.254 set site4=10.0.6.254 :: COMMAND LINE SWITCHES if /i [%1]==[/r] goto start if /i [%1]==[/del] goto start if /i [%1]==[/i] goto inventory if /i [%1]==[/s1] goto site1 if /i [%1]==[/s2] goto site2 if /i [%1]==[/s3] goto site3 if /i [%1]==[/s4] goto site4 if /i [%1]==[/?] goto help if /i [%1]==[/p] set pause=1 & goto start if /i [%1]==[/d] set debug=1 & set pause=1 & echo on & goto start if /i "%~1" GTR "" echo ERROR: Invalid command line switch. & echo. & goto help :start if /i %pause%==1 pause :: EXIT IF IT IS A SERVER :: YOU MAY HAVE A NAMING POLICY FOR YOUR SERVERS :: IF THE FOUR FIRST LETTERS ARE THE SAME FOR ALL :: YOUR SERVERS, THIS PART WILL EXIT THE LOGIN SCRIPT :: eg SITE1DC01, SITE2DC02 etc.. @set computer=%computername% @set computer=%computer:~0,4% if /i %computer% == site goto exit :: FIND CURRENT GATEWAY ipconfig | find /i "gate" > "%userprofile%\gate.txt" :: STRIP DOWN THE RETRIEVED LINE TO ONLY THE IP For /F "Tokens=2* Delims=: usebackq" %%i In ("%userprofile%\gate.txt") Do Set gate=%%i del /f /q "%userprofile%\gate.txt" :: DELETE SPACES IN RESULTS set gate=%gate: =% :: SPLIT UP IP-NUMBER IN FOUR PARTS. for /f "Tokens=1,2,3,4 Delims=." %%i In ("%gate%") Do Set a=%%i& Set b=%%j& Set c=%%k& Set d=%%l :: RE-SET GATEWAY VARIABLE BACK TO STANDARD FORMAT set gate=%a%.%b%.%c%.%d% :: REDIRECT TO LOCATION SPECIFIC SCRIPT if /i %gate% EQU %site1% set location=site1 & set dc=%dc1% if /i %gate% EQU %site2% set location=site2 & set dc=%dc2% if /i %gate% EQU %site3% set location=site3 & set dc=%dc3% if /i %gate% EQU %site4% set location=site4 & set dc=%dc4% if /i [%1]==[/r] goto reinstall if /i [%1]==[/del] goto delprinters :delprinters :: DELETE OLD PRINTERS if %pause%==1 echo Delete old printers - Skip? & set /p skip=y/n?: if /i "%skip%"=="y" goto general if /i [%1]==[/del] del /f /q "%userprofile%\delprinters_%computername%.log" if exist "%userprofile%\delprinters_%computername%.log" goto delprinters_done echo. echo Deleting old network printers . . . this will take a moment. echo. goto delprinters_%location% :: Site1 :delprinters_site1 rundll32 printui.dll,PrintUIEntry /dn /q /n"\\%dc%\printer1" rundll32 printui.dll,PrintUIEntry /dn /q /n"\\%dc%\printer2" :: Site2 :delprinters_site2 rundll32 printui.dll,PrintUIEntry /dn /q /n"\\%dc%\oldprinter1" rundll32 printui.dll,PrintUIEntry /dn /q /n"\\%dc%\oldprinter2" :: Site3 :delprinters_site3 rundll32 printui.dll,PrintUIEntry /dn /q /n"\\%dc%\oldprinter1" rundll32 printui.dll,PrintUIEntry /dn /q /n"\\%dc%\oldprinter2" :: Site4 :delprinters_site4 rundll32 printui.dll,PrintUIEntry /dn /q /n"\\%dc%\oldprinter1" rundll32 printui.dll,PrintUIEntry /dn /q /n"\\%dc%\oldprinter2" :delprinters_done echo Done deleting old network printers. echo. echo. >> "%userprofile%\delprinters_%computername%.log" if /i [%1]==[/r] goto %location%_print if /i [%1]==[/del] goto exit goto general :: END OF delprinters :general :: SET GENERAL OPTIONS if %pause% == 1 echo Set general options - Skip? & set /p skip=y/n?: if /i "%skip%"=="y" goto %location% mode 70,48 echo. echo Setting general regedit settings . . . echo. :: Put all your general commands here goto %location% :: END OF general :site1 :: EXECUTE THIS OPTION WITH THIS SWITCH: "<batchscript>.bat /s1" echo Gate: %gate% (Site1) set location=site1 :site1_map :: NETWORK FOLDER MAPPING if %pause%==1 echo Network mapping - Skip? & set /p skip=y/n?: if /i "%skip%"=="y" goto site1_print net use s: \\%dc%\path1 /persistent:no net use u: \\%dc%\path2 /persistent:no net use n: \\%dc%\path3 /persistent:no net use t: \\%dc%\path4 /persistent:no net use r: \\%dc%\path5 /persistent:no :site1_print :: PRINTERS if %pause%==1 echo Install printers - Skip? & set /p skip=y/n?: if /i "%skip%"=="y" goto exit \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer1" \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer2" \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer3" goto exit :: END OF site1 :site2 :: EXECUTE THIS OPTION WITH THIS SWITCH: "<batchscript>.bat /s2" echo Gate: %gate% (Site2) set location=site2 :site2_map :: NETWORK FOLDER MAPPING if %pause%==1 echo Network mapping - Skip? & set /p skip=y/n?: if /i "%skip%"=="y" goto site2_print net use s: \\%dc%\path1 /persistent:no net use u: \\%dc%\path2 /persistent:no net use n: \\%dc%\path3 /persistent:no net use t: \\%dc%\path4 /persistent:no net use r: \\%dc%\path5 /persistent:no :site2_print :: PRINTERS if %pause%==1 echo Install printers - Skip? & set /p skip=y/n?: if /i "%skip%"=="y" goto exit \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer1" \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer2" \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer3" goto exit :: END OF site2 :site3 :: EXECUTE THIS OPTION WITH THIS SWITCH: "<batchscript>.bat /s3" echo Gate: %gate% (Site3) set location=site3 :site3_map :: NETWORK FOLDER MAPPING if %pause%==1 echo Network mapping - Skip? & set /p skip=y/n?: if /i "%skip%"=="y" goto site3_print net use s: \\%dc%\path1 /persistent:no net use u: \\%dc%\path2 /persistent:no net use n: \\%dc%\path3 /persistent:no net use t: \\%dc%\path4 /persistent:no net use r: \\%dc%\path5 /persistent:no :site3_print :: PRINTERS if %pause%==1 echo Install printers - Skip? & set /p skip=y/n?: if /i "%skip%"=="y" goto exit \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer1" \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer2" \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer3" goto exit :: END OF site3 :site4 :: EXECUTE THIS OPTION WITH THIS SWITCH: "<batchscript>.bat /s4" echo Gate: %gate% (Site4) set location=site4 :site4_map :: NETWORK FOLDER MAPPING if %pause%==1 echo Network mapping - Skip? & set /p skip=y/n?: if /i "%skip%"=="y" goto site4_print net use s: \\%dc%\path1 /persistent:no net use u: \\%dc%\path2 /persistent:no net use n: \\%dc%\path3 /persistent:no net use t: \\%dc%\path4 /persistent:no net use r: \\%dc%\path5 /persistent:no :site4_print :: PRINTERS if %pause%==1 echo Install printers - Skip? & set /p skip=y/n?: if /i "%skip%"=="y" goto exit \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer1" \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer2" \\%dc%\netlogon\con2prt.exe /c "\\%dc%\printer3" goto exit :: END OF site4 :: ########################################### :: ------------------------------------------- :: ------------------------------------------- :: THE BELOW PART IS NOT EXECUTED PER DEFAULT :: ------------------------------------------- :: ------------------------------------------- :: ########################################### :reinstall :: EXECUTE THIS OPTION WITH THIS SWITCH: "<batchscript>.bat /r" cls echo This will delete the flag files and reconnect the echo printers even though the printer may be installed. echo To fully reinstall the printers you will have to echo manually delete the printers from within the Control echo Panel. And execute this script once again. echo. echo Would you like to reinstall printers on this computer? echo. set reinstall=n set /p reinstall=Reinstall printers? y/n: if %reinstall%==y goto reinst if %reinstall%==n echo Good Bye! & goto exit :reinst del /f /q "%userprofile%\delprinters_%computername%.log" goto delprinters :inventory :: EXECUTE THIS OPTION WITH THIS SWITCH: "<batchscript>.bat /i" cls echo This will run inventory on the computer even though echo it has been executed. echo. echo Would you like to inventory this computer? echo. set inventory=n set /p inventory=Run inventory? y/n: if %inventory%==y goto reinv if %inventory%==n echo Good Bye! & goto exit :reinv del /f /q "%appdata%\flag_inv_%computername%.txt" start /min \\%dc%\netlogon\inventory.bat || echo Error executing inventory script. & echo Make sure you have permission to read \\aros.local goto exit :help color 0b echo Niklas Jumlin - All rights reserved. Copyright 2010 echo. echo You may NOT redistribute this; or parts of the; script without the echo permission of the author (Niklas Jumlin). echo. echo Usage: ^<batchscript^>.bat ^<option^> echo. echo A VALID OPTION MAY BE _ONE_ OF THE FOLLOWING: echo. echo /r - This will delete all flag files and reconnect the echo printers even though the printer may be installed. echo To fully reinstall the printers you will have to echo manually delete the printers from within the Control echo Panel. And execute this script with the /r option again. echo. echo /i - Run inventory on the computer even though it has been echo executed. echo. echo /del - Just delete old printers without confirmation, do NOT echo install new ones. echo. echo /p - Pause and ask to run before every actual execution echo or setting. echo. echo /d - Debug mode. Echo On. (Implies /p) echo. echo FORCE LOCATION OPTIONS: echo. echo /s1 - Force the script to go to Site1 specific part. echo. echo /s2 - Force the script to go to Site2 specific part. echo. echo /s3 - Force the script to go to Site3 specific part. echo. echo /s4 - Force the script to go to Site4 specific part. echo. pause goto exit :exit color 07 if /i [%1]==[/?] exit if /i [%1]==[/r] exit if /i [%1]==[/del] exit if exist "%appdata%\flag_inv_%computername%.txt" exit start /min \\%dc%\netlogon\inventory.bat exit