Friday, September 25, 2009

How to Write a Batch File For Windows

  1. Open up Notepad in Windows. You can do this by navigating to Start > Programs > Accessories > Notepad, or simply by entering notepad under Start > Run.
  2. Or open up notepad by C:\WINDOWS\system32\notepad.exe
  3. Save your file before anything, so be sure to follow the instructions closely.

    1. Go to File > Save As... and chose a file name.
    2. Choose your desktop as the location to save, for now. Don't click Save just yet.
    3. Click on the dropdown menu next to "File name". Select "All files" instead of Text Document".
    4. Add .bat to the end of your file name before you save. For example, you would type example.bat.
    5. Click on Save. If you did this correctly, you should see your file name in the title of Windows Notepad. Make sure that it reads as example.bat—not example.bat.txt. Now you are ready to create your batch file.
  4. Type "@echo off" on the first line of your batch file. This will prevent any spaces in the batch file to be read by the program when executed.
  5. Enter your commands. The following example below will show you how to create a batch file that will automatically load wikiHow.com using Internet Explorer.
    • @echo off.
    • REM The following will open wikiHow.com in a new Internet Explorer window.
    • "start Iexplore.exe www.wikihow.com"
    • REM The following will open wikiHow.com in your default browser, but if it is IE and you have another IE window open, then it will hijack that window.
    • "start www.wikihow.com"
  6. Save the file by going to "File>Save" and type in "wikihow.bat".
  7. Run the file by double clicking the file on your desktop.


0 comments:

Post a Comment