Last Update: Sep 24, 2024 | Published: Jan 06, 2009
Batch scripting is a powerful aspect of Windows. If you are unaware, batch scripts are files that are executed by the Command Prompt. In theory, every task that you can complete in Windows using a GUI can be completed using a batch script. This tutorial is an introduction to batch scripting in Windows Vista that will show you how to automatically back up your hard drive and delete your temp files without installing extra software. Additionally, this tutorial will show you how to backup a Web site using Wget and a batch script.
Firstly, as an introduction to batch scripting, create a sample batch file, open Notepad (Start >> All Programs >> Accessories >> Notepad) and save the file as hello.bat onto your desktop. On the first line of the file, type echo “hello” on the second line of the file type echo “the end” and resave your batch file. It should look like the following:
Open Notepad and type the following on the first line:cd c: and on the second line type: xcopy c: e:backup /s /e /h /D and your file should look like the following:
The Windows Vista Disk Cleanup Wizard does a nice job, however it does not delete your temp files unless they are over a week old. If you would like to automatically do this more frequently, open Notepad and type the following on the first line: cd C:Users%username%AppDataLocal and on the second line type: rmdir /S /Q Temp and save the file as removeTemp.bat. Your file should look like the following:
You can automatically make a backup of a Web site by using batch scripting in combination with a third party program called Wget. Wget will allow you to save a backup of every file of a Web site. You can download Wget from the Wget homepage. Create a folder at C:ServerBackup and extract the contents of Wget into it. This is also the location where the contents of the Web site are going to be backed up. Open Notepad and type the following on the first line: cd C:ServerBackup and on the second line type: wget -r -k -p http://www.YourSiteName.com and save the file as ServerBackup.bat. Your file should look like the following:
Here is what you’ve learned to do:
This is only an introduction to batch scripting. With a little imagination, you can accomplish some extremely powerful tasks by using batch scripts.