Creating a batch file at the command prompt in Windows

Sometimes it would be helpful to create your own commands in windows. You can do this using the command or DOS prompt. You can start the command prompt by going to start run and type “cmd”.

You can use the edit command at the command prompt or use an editor like notepad.

A simple script to do some maintenance on your D: drive will serve as an example:

Maintenance.bat

rem Batch file to do maintenance on d drive
rem Make sure we start on c: drive
echo “Starting drive maintence on the D drive”
echo “Changing to the C drive”
c:
rem Run chkdsk on the d drive
echo “Running chkdsk on the D drive”
chkdsk /f /r /x d:
rem Defrag the d drive
echo “Defragging the D drive”
defrag d: -f -v
echo “D drive maintenance complete”
exit

The rem statement is a remark. This allows you to put comments in your batch file.
The echo statement prints to the screen. This allows you to follow the progress of your script.
the chkdsk runs check disk on drive D
the defrag defrags drive D
the exit statement exits the script.

You can get help on each command by type “help command”. To get a list of available commands type “help” by it self.

You can then put the script as a scheduled task to run on a regular basis.

For MyPTSMail users support is free.

For more information or tech support by phone on the command prompt call 410-838-5100 or email us experts@expertsinunix.com.
Skype: pts.support

 
creating_a_batch_file_at_the_command_prompt_in_windows.txt · Last modified: 2010/08/23 10:32 by admin
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki