Question about Computers & Internet

3 Answers

How to create simple batch files - Computers & Internet

Posted by on

3 Answers

  • Level 2:

    An expert who has achieved level 2 by getting 100 points

    MVP:

    An expert that got 5 achievements.

    Vice President:

    An expert whose answer got voted for 100 times.

    Sergeant:

    An expert that has over 500 points.

  • Expert
  • 158 Answers

Creating a batch file
MS-DOS users
Microsoft Windows and other users

MS-DOS users
To create a basic batch file in MS-DOS, follow the below steps that give you an example of how to create a basic batch file.

  1. Open an MS-DOS command window or get to MS-DOS. Additional information about doing this can be found on document CHDOS.
  2. At the MS-DOS prompt, type: edit test.bat and press enter.
  3. If typed properly, you should now be in a blue screen. Within the screen, type:

    pause
    dir c:\windows
    dir c:\windows\system

  4. Once the above three lines have been typed in, click File and choose exit; when prompted to save, click "Yes." Users who do not have a mouse cursor can accomplish this same task by pressing ALT+F to access the file menu, then pressing "X" to exit, and pressing enter to save changes.
  5. Once you are back at the MS-DOS prompt, type: test and press enter. This will execute the test.bat file and begin running the file. Because the first line is pause, you will first be prompted to press a key. Once you press a key the batch file will run line-by-line; in this case, listing the files in the windows and windows\system directories.
If you wish to add more lines to this batch file you would simply type "edit test.bat" to edit the file again.
Additional information about the MS-DOS edit command can be found on our edit command page. Some versions of MS-DOS and bootable diskettes may not have the edit command; if this is the case, you would either need to obtain the edit.com file to access this file or use the copy con command.




Microsoft Windows and other users
A Windows user can still use the above MS-DOS steps if they wish to create a batch file. If, however, you're more comfortable using Microsoft Windows or your operating system, you can use any text editor, such as Notepad or Wordpad, to create your batch files, as long as the file extension ends with .bat. In the below example we use the Windows notepad to create a batch file.
  1. Click Start
  2. Click Run
  3. Type: notepad and press enter.
  4. Once notepad is open, type the below lines in the file or copy and paste the below lines into notepad.

    @echo off
    echo Hello this is a test batch file
    pause
    dir c:\windows

  5. Click File and click Save; browse to where you want to save the file. For the file name, type "test.bat", and if your version of Windows has a "Save as type" option, choose "All files", otherwise it will save as a text file. Once all of this has been done click the Save button and exit notepad.
  6. Now, to run the batch file, simply double-click or run the file like any other program. Once the batch file has completed running it will close the window automatically.

Posted on Jan 04, 2011

  • Level 1:

    An expert who has achieved level 1.

    Corporal:

    An expert that has over 10 points.

  • Contributor
  • 4 Answers

I've been (no joke) a professional Batch File Programmer for about 5 years(before I joined the Navy). If anyone needs help, just ask. :)

Posted on Oct 04, 2012

  • Level 1:

    An expert who has achieved level 1.

    MVP:

    An expert that got 5 achievements.

    Champion:

    An expert who has answered 200 questions.

    Governor:

    An expert whose answer got voted for 20 times.

  • Contributor
  • 331 Answers

Batch files need to end in the file name .bat. A super simple way to do it in dos would be to type at the C:\> type: copy con: filename.bat (this will create the file) then type the echo command "echo" is used to put text on the screen. Then, end with a control +z which will create a ^Z and it will say "one file copied" this will result in a simple batch file that says whatever is put after echo. To launch the file, type filename.bat ... So, to recap it should look similar to this:

copy con: filename.bat
echo Hi World
^Z (control + Z)

Posted on Jan 04, 2011

1 Suggested Answer

6ya6ya
  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

Hi,
a 6ya expert can help you resolve that issue over the phone in a minute or two.
best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.
goodluck!

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

2 Answers

How to Create a Batch File?


Use "notepad" to type in the commands you want in the batch. Save the file with the extension, "cmd" as in, "batch.cmd". You have a batch file now. It's just commands in a file.

Oct 18, 2016 | Computers & Internet

Tip

How to create a batch file on windows xp.


To create a batch file that would be very helpful I suggest downloading notepad++ it's made for programming.First off open up notepad++ and go to
languages and click on batch then type in "@echo off" at the beginning of every batch file you need to type that in.Next type in:
______________________________________________________________

@echo off
echo.
echo What would you like to do today?
echo.
echo 1)Notepad
echo 2)Paint
echo 3)Calculator
echo.

set /p web=Type in Option:
if "%web%"=="1" ("%SystemRoot%\system32\notepad.exe") else (exit)
if "%web%"=="2" ("%SystemRoot%\system32\mspaint.exe") else (exit)
if "%web%"=="3" ("%SystemRoot%\system32\calc.exe") else (exit)

______________________________________________________________

You just created a batch file menu now save this file to the desktop as
"Menu.bat".Now that you have the file saved download this free batch file compiler called "battoexe" so nobody can edit or destroy you batch files.
That's it you have made your first batch file visit my website at www.wix.com/Firestorm002/Batch101.

on Jul 18, 2010 | Computers & Internet

Tip

How to create a batch file ...


Did you ever get frustrated when you had to type a long list of commands in the command prompt window, even when those commands were already there on some site... I know it's very frustrating that ctrl+v doesn't seem to paste commands in the command prompt, but there is a way, and it's very very simple...

You can copy and paste those commands, to a new text document, and then select save as, hit the drop down menu where it says text document(*.txt), select all files, and name the file as filename.bat...

then just double click and run it from your desktop, or from anywhere else too...

you can execute the batch file in the recovery console as well ... just browse to the folder where the file is and type the name of the file

Good luck !!

on Dec 01, 2009 | Computers & Internet

1 Answer

What happens wen rtc Batt is unloaded


Hello. batt files or batch files are used by your operating system to run a list of commands created by ms-dos or by you. A good example of a batch file is the autoexec.bat which is loaded each time the computer boots to MS-DOS. Batch files are like shortcuts on your desktop, when they are run they pass information through the command line and these sets of instructions run commands or programs on your computer. Did that help?

Feb 09, 2014 | Acer Predator G3620-UR308 - Core i7 3770...

2 Answers

Can anyone explain how batch file works?


This is kind of tricky not knowing how familiar you are with the commandline, but a batch file simply contains single commands and executes them in order (usually from top to bottom). A batch file (or bash script in Linux) can be very helpful if you have to run certain commands over and over again, so you don't have to write them by hand.

An Example: You want to store your network settings in a text file.
You open the command prompt (WIN+R) and type this line:
mkdir C:\Network
Then you type this line:
ipconfig /all > C:\Network\ipconfig.txt
The first line creates a folder on your C: drive called "Network"
The second line runs the ipconfig command and saves it as a text file in that new folder.

To make a batch file, you open Notepad and insert the two lines. Then save it as "IP.bat" (make sure not to save it as "IP.bat.txt"! This is the most common mistake. If you save a file from Notepad, select "All Files" in the "Save As Type" dialog. Otherwise it will save it as a .txt file and you have to rename it later.)

Now you can double click the batch file and it runs all commands in the file.

You can also see the danger. If you run a batch file and don't know what it really does, it can destroy your whole system. So make sure you understand it and/or get it from a trustworthy source.

A nice example of how complex a batch file can be is here:
AllHelp.bat

Copy the content into a text file, save it as AllHelp.bat, run it and it will create a webpage with all available DOS commands.

Hope this helps - otherwise let me know if you have specific questions.
Enjoy!

Feb 26, 2012 | HEWLETT-PACKARD Computers & Internet

Tip

Create a password protected folder without any special software


In an earlier post I had written about how to create an invisible folder. That’s a method to create a merely invisible folder with no real protection.
Now, here we will see how to create a folder that will not just be invisible, but also require a password to reveal it and open it. The best part is that you don’t need any special software to do this. Just plain old Notepad is all that you need.
Here is the code that you need:
cls
@ECHO OFF
title Folder Personal
if EXIST “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}” goto UNLOCK
if NOT EXIST Personal goto MDLOCKER
:CONFIRM
echo Are you sure u want to Lock the folder(Y/N)
set/p “cho=>”
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Personal “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}”
attrib +h +s “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}”
echo Folder locked
goto End
:UNLOCK
echo Enter password to Unlock folder
set/p “pass=>”
if NOT %pass%==pwd123 HERE goto FAIL
attrib -h -s “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}”
ren “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}” Personal
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Personal
echo Personal created successfully
goto End
:End
Now here is what you need to do:
Just copy the above code and paste it into Notepad. Save it by giving it any name you choose. Assuming, the file is called secret.txt, change the extension to ‘.bat‘ so that the new name becomes secret.bat. What you get is a batch file. You could actually save one step by saving the file in Notepad directly as secret.bat by enclosing the file name like this: “secret.bat” . This batch file is the one that you need. You can edit this batch file to change the folder name and the password. To change the name of the folder that is created, change the ‘Personal’ (in bold in the above code) to any another name you choose. Likewise change the ‘pwd123′ (in red in the code) to anything else.
Now let’s see how to use it. Place the file in the location where you would like to create your protected folder. Run the batch file by double clicking on it. This will create a folder named Personal in the same location as the batch file. You can now open this folder and place any files in it. Once you are finished, run the batch file again. You will be asked whether you want to lock the folder. Entry ‘Y’ (for Yes) and hit Enter. The folder becomes invisible. To retrieve the folder, run the batch file again. You will be prompted to enter the password. Enter the password, hit enter and voila! the folder appears.
Important: The batch file acts like a key to open the locked folder. So once you have created and locked a folder, do not keep the batch file in the same location since anybody can open the batch file and view your password. So I would suggest that you keep the batch file in a separate and safe place or better still keep it on your pen drive or flash drive. That way when you want to open the folder just copy the batch file to the location where you have your protected folder and run it.
Do remember that the above method is not intended to act as a substitute for the numerous free and commercial softwares that are specifically designed to provide security and encryption to your data.
Update: I got comments saying the code does not work. Of course I did check it before posting it here. But I have identified the problem. The problem is with the straight double quotes used in the code in this post. Once you copy the code you would also need to change each of the double quotes with your keyboard double quotes. That might seem a lot of work for some. So I thought it would be easier to give away the batch file itself. You can download the file here. (Use right-click and ‘Save Target as’ or ‘Save Link as’).

on Mar 20, 2008 | HP Pavilion a1410n (ER890AA) PC Desktop

2 Answers

Copying to c:\ in vista using batch files..


You need to left click the batch file and "Run as Administrator".

Nov 01, 2009 | Microsoft Windows Vista Ultimate Edition

2 Answers

BATCH FILE


in batch programming you can use your DOS command internal/extarnal or any program you can run.

You have to just write your commands in the sequence in which you want to run them, in a text format, and save them with a extension of .BAT. Thats all you have to do in a batch file program.

Click on this link to see some examples from Micro Soft:

Please don't forget to rate this........ :)

Thanks
Iqbal

Mar 29, 2008 | Computers & Internet

2 Answers

How to edit registry


1) to edit registry go to start / select run and type regedit. from there you are able to edit registry values. BEWARE because editing registry values may make your windows stop working. you should know what you are doing and you are responsible of the cosnequenses 2) a bat file is a batch file. Batch files are files that allow MS-DOS and Microsoft Windows users to create a lists of commands and/or programs to run once the batch file has been executed. 3) create a file called autorun.inf and type inside [autorun] open=file.exe save your file and write it in the cd you want to autorun the file.exe part must be replaced with the executable you want to load when your CD autoruns

Oct 08, 2007 | Microsoft Windows XP Professional With...

Not finding what you are looking for?
Computers & Internet Logo

Related Topics:

221 people viewed this question

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Doctor PC
Doctor PC

Level 3 Expert

7733 Answers

kakima

Level 3 Expert

102366 Answers

David Payne
David Payne

Level 3 Expert

14161 Answers

Are you a Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...