PDF download Download Article
Open and execute a batch file on a PC, Mac, and even Linux
PDF download Download Article

This wikiHow teaches you how to run a BAT file—also known as a batch file—on a Windows computer. Batch files have many purposes, such as automating frequently used tasks. You can run them in the normal File Explorer , or you can launch them from the command line of the Command Prompt . As a bonus, we’ll also teach you how to run a BAT file on Mac and Linux .

Ways to Run BAT Files on Windows

Open File Explorer and navigate to the batch file. Double-click the batch file to run it. If you need to run it as an administrator, right-click the file and select Run as administrator . To run it from CMD, enter the folder containing the batch file, type the file's name, then press Enter .

Method 1
Method 1 of 3:

Using File Explorer

PDF download Download Article
  1. 1
    Press Win + E to open File Explorer. You can use the keyboard to open File Explorer, or click the Windows Start menu, type “file explorer,” and click the File Explorer icon, which resembles a manila folder with a blue clip.
    • Warning: Be careful when running BAT files you received over email or downloaded from the internet. Cybercriminals can use BAT files to run exploits on your system that can compromise your privacy and security. If you don’t know where the BAT file came from or what it does, don’t run it.
    • Be sure to run a virus scan on any BAT files you download before running them.
  2. Navigate to the location of your batch file, or you can search for it by clicking This PC in the left pane and typing the filename in the search bar at the top-right.
    Advertisement
  3. Normally, to run a batch file, all that is needed is to double-click the file, and the actions contained in the file will run in the background. You may see a black command prompt window open for a second and then close, which just means the batch file doesn't require any input from you.
    • If you want to see what the batch file is actually doing at the command line, check out the command prompt method.
  4. If the batch file contains tasks that require administrative access, you will need to run it as an administrator. Never do this on a batch file you don't trust! To run a BAT file as an administrator, right-click the file and select Run as administrator .
    • In order to run a file as an administrator, you need to be signed into an account that has administrative privileges. If you do not have administrative privileges, talk to your administrator.
    • Oftentimes, batch files don't do much visually on your computer, and running them will make changes to your computer behind the scenes. Be sure you understand what your batch file is supposed to do, as it may have run successfully even though it didn't look like anything happened.
  5. Advertisement
Method 2
Method 2 of 3:

Using Command Prompt

PDF download Download Article
  1. Running a BAT file at the command prompt is usually the preferred way, as it allows you to see any errors or prompts that pop up. An easy way to open the command prompt is to press the Windows key on your keyboard, type cmd , and then click Command Prompt in the search results.
    • If the BAT file you want to run contains administrator-level commands, you will need to open the command prompt as an administrator. You should only do this if you are sure you trust the batch file.
      • To open command prompt as an administrator, right-click Command Prompt in the search results and select Run as administrator .
    • Warning: Be careful when running BAT files you received over email or downloaded from the internet. Cybercriminals can use BAT files to run exploits on your system that may be harmful to your computer or compromise your privacy and security. If you don’t know where the BAT file came from or what it does, don’t run it. Be sure to run a virus scan on any BAT files you download before running them. it. [1]
  2. Type the letters cd , which is the command to "change directory." Then, press the spacebar once, and enter the full path to the location in which the batch file is saved.
    • For example, if your batch file is located in in your Documents folder, type cd Documents and press Enter .
    • If you're not sure how to find the BAT file's path, check out our guide to finding a file's path on Windows .
  3. That means typing the filename and extension, ending with .bat at the end. For example, if your batch file is named "install", then you would type install.bat into the command prompt, and then press Enter . [2]
    • Note any errors that appear in the command prompt from running the batch file, as that may be helpful in troubleshooting something wrong with the batch file's code.
  4. Advertisement
Method 3
Method 3 of 3:

Using Mac and Linux

PDF download Download Article
  1. 1
    Convert the BAT file to a shell script. BAT files contain commands that only work on Windows. If you want to run the file on a Mac or Linux machine, you'll need to convert it to a shell script , which requires knowing how to translate Windows command-line commands to Bash. To do so, you will need to open the BAT file in a text editor like TextEdit for Mac or Nano for Linux.
    • You will need to go through the script and convert all Windows-specific commands to BASH (or Mac/Linux) commands.
    • Then, you will need to save the file with the .sh file extension. For example, helloworld.sh .
  2. 2
    Run a BAT file on Mac or Linux. Once you have converted the file to a shell file, you can use the following steps to run the file on Mac or Linux:
    • Open the Terminal .
    • Type cd followed by a space and the location of the file. For example cd /home/users/jeff/documents
    • Run the following commands to run the file:
      • Make the shell script executable by typing chmod +x <filename.sh> .
      • Then, type ./<filename.sh> and press Enter or Return .
      • Replace <filename.sh> with the name of your file.
  3. 3
    Install a Windows emulator as an alternative. Alternatively, if you want to run BAT files in a version of Windows that runs on macOS or Linux, you can run it in WINE. WINE is widely available on Linux and pretty easy to install . To install WINE on Mac, you will first need to install Homebrew. Use the following steps to install WINE: [3]
    • Open the Terminal.
    • Enter the following command and press Enter to install Homebrew (Mac only):
    • Enter one of the following commands and press Enter to install WINE: [4]
      • Mac: brew install --cask wine-stable
      • Ubuntu/Debian: sudo apt install --install-recommends winehq-stable
      • Fedora/RedHat/CentOS: dnf install winehq-stable
  4. Advertisement

Expert Q&A

Ask a Question
      Advertisement

      Video

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!

      About This Article

      Thanks to all authors for creating a page that has been read 240,424 times.

      Is this article up to date?

      Advertisement