Home > Windows Server Tips > Windows Systems Management and Administration > Why batch files are still useful
Windows Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

WINDOWS SYSTEMS MANAGEMENT AND ADMINISTRATION

Why batch files are still useful


Tim Fenner
07.07.2005
Rating: -4.46- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Please let us know how useful you find this tip by rating it below. Do you have a useful Windows tip, timesaver or workaround to share? Submit it to our monthly tip contest and you could win a prize! And don't forget to go in and rate other tips users have submitted this month:
Easy Mail Server changes
Add or modify the registry via group policy
Use Windows XP sysprep to create images
Speed up remote access to network resources
Use HP's JetDirect printer server to count bad packets
Protect Win XP files during power outage


Scripting and coding is fine for those who wish to spend their day learning all the ins and outs of the programming language. But for me, reusing some old batch file commands has saved me time and gets the job done just as well (without having to teach this "old dog" any new tricks). If you are like me and know how to create batch files, then this tip will be a basic review for you. If you are new, then I hope you will find this tip useful.

Typically these batch file commands are universal between Windows versions, but you may find some that are not. However, there is typically a substitute for the version you wish to use.

To create a batch file, you need only open Notepad.exe, type in the batch syntax, then save the file as a .bat extension (batchfile.bat).

Batch files are great for logon scripts, for automating PC environment configurations and for simply making IT life easier.

If you ever want to know more about a batch file command, typically you just have to type /? after the command to get a list of options.

I have attached examples of batch files for you to review and use below. Some of these include:
-Create, copy and delete files/folders
-Create ODBCs
-Create mapped drives and install network printers
-Condition checking
-Synchronizing time

Example of Windows Batch File Commands:


REM #====================================
REM #
REM # Description: Creating comment Lines REM # These are used to explain what your REM # batch files are doing 
REM #====================================


REM - Type REM in front of every line you wish REM - the batch file to ignore.
Basically REM - they are used for comment lines, like these: REM #==================================== REM # REM # Description: @ECHO states whether to REM # have the batch file present the text REM # it is running on the screen - On or Off REM # REM #==================================== @ECHO off @ECHO on REM #========================================= REM # REM # Create directories - The example shows how to REM # create a folder on the c: drive REM # REM #============================================ c: cd md C:folder1 md c:folder1folder2 REM #============================================ REM # REM # Delete, copy and set attributes for files REM # The quotes are needed if the REM # path to the file is broken, such as REM # c:documents and settingsfile1.txt REM # Here I delete, copy, remove Read only and set REM # the hidden attributes on some files REM # REM #============================================ del "C:file.txt" copy c:file2.txt c:folder1folder2 /Y attrib -r c:folder1folder2file2.txt attrib +h c:folder1folder2file2.txt REM #==================================== REM # REM # Description: The Net command can do a lot REM # and one is synchronizing the time between REM # two systems. Running the following will REM # synchronize the time on the system with REM # a system called server1. Also the second REM # example synchs the PC1's time to an NTP REM # server's time REM # REM #=================================== net time server1 /set /y NET TIME PC1 /SETNTP:ntpservername REM #=================================== REM # REM # Description: Mapping Network Drives REM # allows a system to set a drive letter REM # to connect to a remote network share REM # So P: will map to server1's shared REM # folder called share1. Also, I am REM # deleting a H: mapped drive REM # REM #=================================== net use p: server1share1 /persistant:yes net use h: /delete REM #===================================== REM # REM # Conditional statements allow you to REM # set conditions for the batch file to REM # meet before processing the rest of the REM # batch. Such as checking for the existence REM # of a file and process the batch file REM # accordingly. REM # REM #===================================== if exist c:file.txt (goto 2) ELSE goto 1 :1 @ECHO on ECHO The file IS NOT there @echo off goto end :2 @ECHO on ECHO The file IS there @echo off goto end :END REM #======================================= REM # REM # Description: Installs/removes network printers REM # If the printer driver is installed on the REM # system running this batch file, it will connect REM # to the shared printer (also, the server maybe REM # configured to download the printer driver for REM # clients requesting it) REM # REM #========================================= REM # Used to delete network printers rundll32 printui.dll,PrintUIEntry /q /dn /n server1sharedprinter1 REM # Used to create network printers rundll32 printui.dll,PrintUIEntry /in /c server1 /n server1sharedprinter2 REM #========================================== REM # REM # Create ODBCs for connecting to backend databases REM # The example shows a connection to a SQL server REM # using a Windows NT login REM # REM #=========================================== odbcconf /a {configsysdsn "SQL Server" "DSN=ODBCname|Database=DBname|SERVER=server1instance1|Trusted_Connection=yes"}

For more examples, use your favorite search engine and look for Windows Batch File Commands. You'll turn up sites like these:
10 most used batch commands
An A-Z Index of the Windows NT/XP command line.

Rate this Tip
To rate tips, you must be a member of SearchWindowsServer.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Windows Systems and Network Management Tools and Techniques
A first look at Internet Information Services 7.0
Windows registry hack improves offline file access for mobile users
Reducing the size of network backups in Windows
Monitor network bandwidth with CyberGauge
How to format NTFS: More tricks to improve file system performance
Key enhancements to SCCM give admins more control over assets, licensing
Archiving information with New-Item in Windows PowerShell
The new Microsoft System Center: What happened to SMS and MOM?
New Russinovich tool scans for open file references from command line
Identify file extension types with TrID

Windows Systems Management and Administration
Tips for Windows domain controller optimization
Quick hits: Troubleshooting service account failure, batch job execution
Case Study: Troubleshooting Windows service dependency failures
Troubleshooting common Windows service failures
How to format NTFS: More tricks to improve file system performance
Key enhancements to SCCM give admins more control over assets, licensing
Windows scripting secrets for disk quota management
Optimizing NTFS file system performance
The new Microsoft System Center: What happened to SMS and MOM?
New Russinovich tool scans for open file references from command line

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2004 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts