- How to Open Command Prompt
- Open Command Prompt to Execute Commands in Windows 10, 8, 7, Vista, & XP
- Open Command Prompt in Windows 10
- Open Command Prompt Through the Start Menu
- Open Command Prompt Using Power User Menu
- Open Command Prompt in Windows 8 or 8.1
- Open Command Prompt in Windows 7, Vista, or XP
- Other Ways to Open Command Prompt
- Elevated Command Prompts and Old Windows Versions
- Run C++ in command prompt — Windows
- 11 Answers 11
- How to create and run batch file on Windows 10
- How to create a batch file on Windows 10
- Create basic batch file
- Create advanced batch file
- Create actionable batch file
- How to run a batch file on Windows 10
- Run batch file on-demand
- Command Prompt
- File Explorer
- Run batch file on schedule
- Run batch files on startup
- More Windows 10 resources
- The Dell XPS 15 is our choice for best 15-inch laptop
- Halo: MCC’s live service elements make it better, not worse
- Microsoft’s Surface Duo is not ‘failing up’
- These are the best PC sticks when you’re on the move
How to Open Command Prompt
Open Command Prompt to Execute Commands in Windows 10, 8, 7, Vista, & XP
Some popular Command Prompt commands you might have heard of include ping, netstat, tracert, shutdown, and attrib, but there are many more. We have a complete list here.
While Command Prompt probably isn’t a tool most of you will use on a regular basis, it can really come in handy now and then, maybe to troubleshoot a specific Windows problem or to automate some kind of task.
How you open Command Prompt differs between Windows versions, so you’ll find steps below for Windows 10, Windows 8 or Windows 8.1, and Windows 7, Windows Vista, and Windows XP. See What Version of Windows Do I Have? if you’re not sure.
Open Command Prompt in Windows 10
Select the Start button.
Type cmd.
Select Command Prompt from the list.
Open Command Prompt Through the Start Menu
Another way to open Command Prompt in Windows 10 is to look in its Start menu folder:
Select the Start button.
Select the Windows System folder from the list.
Choose Command Prompt from the folder group.
Open Command Prompt Using Power User Menu
One more method in Windows 10 is through the Power User Menu. If you’re using a keyboard or mouse, choose Command Prompt from the menu that appears after pressing Win+X or right-clicking the Start button.
You might see Windows PowerShell options in the Power User Menu instead of Command Prompt. In more recent versions of Windows 10, Command Prompt has been replaced by PowerShell, but you can still access it from the Power User Menu by editing the taskbar settings.
Open Command Prompt in Windows 8 or 8.1
Select the Start button and then swipe up to show the Apps screen. You can accomplish the same thing with a mouse by selecting the down arrow icon at the bottom of the screen.
Prior to the Windows 8.1 update, the Apps screen can be accessed from the Start screen by swiping up from the bottom of the screen, or right-clicking anywhere, and then choosing All apps.
If you’re using a keyboard or mouse, a really quick way to open a Command Prompt window in Windows 8 is through the Power User Menu—just hold the WIN and X keys down together, or right-click the Start button, and choose Command Prompt.
Swipe or scroll to the right on the Apps screen to locate the Windows System section heading.
Select Command Prompt. You can now execute whatever command you needed to run.
See our List of Windows 8 Command Prompt Commands for a complete list of the commands available through Command Prompt in Windows 8, including short descriptions and links to more in-depth information if we have it.
Open Command Prompt in Windows 7, Vista, or XP
Open the Start menu from the bottom-left corner of the screen.
In Windows 7 and Windows Vista, it’s a bit faster to enter command in the search box at the bottom of the Start menu and then choose Command Prompt when it appears in the results.
Go to All Programs > Accessories.
Choose Command Prompt from the list of programs.
Here’s our List of Windows 7 Commands and List of Windows XP Commands if you need a command reference for any of those versions of Windows.
Other Ways to Open Command Prompt
Command Prompt in Windows XP through Windows 10 can also be opened with a command. This is especially helpful if you like using the Run dialog box or if Windows Explorer has crashed and the Start menu is inaccessible (and thus the directions above don’t work).
To do this, enter cmd into the command-line interface. This can be in the Run dialog box (WIN+R) or Task Manager’s File > Run new task menu.
Elevated Command Prompts and Old Windows Versions
In versions of Windows released before Windows XP, like Windows 98 and Windows 95, Command Prompt doesn’t exist. However, the older and very similar MS-DOS Prompt does. This program is located in the Start menu and can be opened with the command run command.
Some commands, like the sfc command that’s used to repair Windows files, require that Command Prompt be opened as an administrator before they can be executed. You’ll know if this is the case if you get a message like one of these after trying to execute the command:
- check that you have administrative rights
- . command can only be executed from an elevated command prompt
- you must be an administrator
See How to Open an Elevated Command Prompt for help starting Command Prompt as an administrator, a process that’s a bit more complicated than what’s outlined above.
Run C++ in command prompt — Windows
I know that everyone uses an IDE nowadays, but I just find it simpler to write my code in notepad++, compile it using a command prompt command, and run it from there too. At least that works for Java and Python. I’ve tried to get my head around how to do that with C++, and haven’t been able to find anything good. Is there any compiler (like Java’s JDK) that I can stick into my path and use the C++ equivalent of javac and java to run and compile my code from CMD?
Note: please don’t post answers and comments about how IDEs are better — I know they are. I’m just used to doing it the old way 😀
11 Answers 11
It depends on what compiler you’re using.
For example, if you are using Visual C++ .NET 2010 Express, run Visual C++ 2010 Express Command Prompt from the start menu, and you can simply compile and run the code.
or from the regular command line, you can run vcvars32.bat first to set up the environment. Alternatively search for setvcvars.cmd (part of a FLOSS project) and use that to even locate the installed VS and have it call vcvars32.bat for you.
Please check your compiler’s manual for command lines.
Steps to perform the task:
First, download and install the compiler.
Then, type the C/C++ program and save it.
Then, open the command line and change directory to the particular one where the source file is stored, using cd like so:
Then, to compile, type in the command prompt:
Finally, to run the code, type:
If you’re running Windows then make use of this:
g++ is the name of the compiler and -o is the option needed for creating a .o file. Program (without .cpp suffix) is the exe file and program.cpp is your source file that you want to compile.
Use this shortcut to run the .exe file of the program. This may run in Ubuntu but you may have to use .out suffix instead of .exe . Use this handy batch script I made to execute your programs on Windows:
save it as cppExecutor.bat
Also you could use the following commands on Unix (Linux and Mac) OS:
If you want to use gcc :
With the shortcut:
Sure, it’s how most compilers got started. GCC is probably the most popular (comes with most flavors of *nix). Syntax is just gcc my_source_code.cpp , or gcc -o my_executable.exe my_source_code.cpp . It gets more complicated, of course, when you have multiple source files (as in implementation; anything #include d works automatically as long as GCC can find it).
MinGW appears to be a version of GCC for Windows, if that’s what you’re using. I haven’t tried it though.
Pretty sure most IDEs also include a command line interface. I know Visual Studio does, though I have never used it.
I really don’t see what your problem is, the question is rather unspecific. Given Notepad++ I assume you use Windows.
You have so many options here, from the MinGW (using the GCC tool chain and GNU make ) to using a modern MSVC. You can use the WDK ( ddkbuild.bat/.cmd or plain build.exe ), the Windows SDK ( nmake.exe ), other tools such as premake and CMake, or msbuild that comes with MSVC and the Windows SDK.
I mean the compiler names will differ, cl.exe for MSVC and the WDK and Windows SDK, gcc.exe for MinGW, but even from the console it is customary to organize your project in some way. This is what make and friends were invented for after all.
So to know the command line switches of your particular compiler consult the manual of that very compiler. To find ways to automate your build (i.e. the ability to run a simple command instead of a complex command line), you could sift through the list on Wikipedia or pick one of the tools I mentioned above and go with that.
Side-note: it isn’t necessary to ask people not to mention IDEs. Most professional developers have automated their builds to run from a command line and not from within the IDE (as during the development cycle for example), because there are so many advantages to that approach.
How to create and run batch file on Windows 10
Source: Windows Central
On Windows 10, a batch file is a special text file that typically has a .bat extension, and it includes one or more commands that Command Prompt can understand and run in sequence to perform various actions.
Usually, you can type commands manually to perform a particular task or change system settings on Windows 10. However, a batch file simplifies the work of retyping commands, saving you time and potentially irreversible mistakes.
You can also use other tools like PowerShell to write even more advanced scripts. However, using batch files with Command Prompt is a convenient option when you need to run commands to change settings, automate routines, and start apps or launch websites.
In this Windows 10 guide, we’ll walk you through the steps to create and run your first batch file on your device. Also, we’ll outline the steps to create advanced scripts and automate scripts using the Task Scheduler.
How to create a batch file on Windows 10
The process of creating a batch (script or batch script) file is simple. You only need a text editor and some basic knowledge typing Command Prompt native commands. In the instructions below, we’ll outline the steps for writing a basic and advanced batch file, as well as the steps to write a script to change the system settings on Windows 10.
Create basic batch file
To create a basic batch file on Windows 10, use these steps:
- Open Start.
- Search for Notepad and click the top result to open the app.
Type the following lines in the text file to create a batch file:
Source: Windows Central
The above script outputs the phrase, «Congratulations! Your first batch file executed successfully» on the terminal screen.
Source: Windows Central
- @ECHO OFF — Disables the display prompt to show only the message on a clean line. Usually, this line goes at the beginning of the file. (You can use this command without «@,» but the symbol hides the command being executed to create a cleaner return.)
- ECHO — Prints any text on the screen.
- PAUSE — Keeps the window open after executing the command. If you don’t use this command, the window will close automatically as soon as the script finishes running. You can use this command at the end of the script or after a specific command when running multiple tasks, and you want to pause between them.
Type a name for the script — for example, first_basic_batch.bat.
Quick note: While batch files typically use the .bat file extensions, you can also find scripts using the .cmd or .btm file extensions.
Once you complete the steps, you can double-click the file to run it, or you can use the steps below to learn the different ways to execute a batch file on Windows 10.
Create advanced batch file
To create an advanced batch file to execute multiple commands, use these steps:
- Open Start.
- Search for Notepad and click the top result to open the app.
Type the following lines in the text file to create a more advanced batch file:
Source: Windows Central
The above script runs a series of commands to query different system information. Then it groups them into three different categories, including «WINDOWS INFO,» «HARDWARE INFO,» and «NETWORK INFO.» The «start» command will also open a Microsoft support website listing the official Windows 10 system requirements on your default web browser, which you can check against your information.
Source: Windows Central
- @ECHO OFF — Disables the display prompt to show only the message on a clean line. Usually, this line goes at the beginning of the file. (You can use this command without «@,» but the symbol hides the command being executed for a cleaner return.)
- TITLE — Displays a custom name in the title bar of the window.
- :: — Allows you to write comments and documentation information. These details are ignored when the batch file runs.
- ECHO — Prints the exact text on the screen.
- START — Lets you launch an app or website with the default web browser.
- PAUSE — Keeps the window open after executing the command. If you don’t use this command, the window will close automatically as soon as the script finishes running. You can use this command at the end of the script or after a specific command when running multiple tasks, and you want to pause between them.
After you complete the steps, double-click the .bat file to run it, or you can use the steps below to learn the different ways to run a batch.
Create actionable batch file
In addition to executing and displaying content in a Command Prompt window, you can also write non-interactive batch scripts to perform virtually any task you need.
To create a batch file that runs a specific command without user interaction, use these steps:
- Open Start.
- Search for Notepad and click the top result to open the app.
Copy and paste the following command in the text file:
Source: Windows Central
Quick note: In the screenshot, you’ll notice the «pause» command, but it’s not required. It was added in this example to take a screenshot of the terminal. If you’re accessing the files from another computer that uses a specific username and password, don’t forget to use the /user: option with the necessary credentials.
The above script includes a simple command to map a network folder as a drive inside File Explorer using the «Z» drive letter.
Source: Windows Central
Once you complete the steps, the batch file will map the network folder with the specified settings without opening a Command Prompt window. While we only used one command in this particular file, you can include as many commands as you like, as long as you write them one per line.
How to run a batch file on Windows 10
On Windows 10, you can run a batch file in at least three ways. You can run it on-demand using File Explorer or Command Prompt. You can create a task with Task Scheduler to run it on schedule. Or you can place the script in the «Startup» folder to run it every time you sign in to your Windows 10 account.
Run batch file on-demand
If you need to run a script on-demand, you have two choices, including Command Prompt or File Explorer.
Command Prompt
To run a batch file with Command Prompt, use these steps.
- Open Start.
- Search for Command Prompt, right-click the top result, and select the Run as administrator option.
Type the path and name of the batch file, and press Enter:
For example, the following command runs the batch file located in the «scripts» folder, inside the «Downloads» folder:
Source: Windows Central
After you complete the steps, the console will return the results, and the window won’t close even if the script doesn’t include the «PAUSE» command.
File Explorer
To run a batch file with File Explorer, use these steps:
- Open File Explorer.
- Browse to the folder with the script.
- Double-click the batch file to run it.
(Optional) If you execute a command that requires administrator privileges, you’ll need to run the script as an admin by right-clicking the batch file and selecting the Run as administrator option.
Source: Windows Central
Once you complete the steps, the batch will run each command in sequence displaying the results in the terminal.
Run batch file on schedule
To schedule a batch file on Windows 10, you can use the Task Scheduler with these steps:
- Open Start.
- Search for Task Scheduler and click the top result to open the app.
- Right-click the «Task Scheduler Library» branch and select the New Folder option.
Type a name for the folder — for example, MyScripts.
Quick note: It’s not a requirement to create a folder, but it’s recommended to keep tasks organized.
Select the Create Basic Task option.
Source: Windows Central
In the «Name» field, type a descriptive name for the task — for example, SystemInfoBatch.
Source: Windows Central
Select the Monthly option.
Source: Windows Central
Quick note: On Windows 10, the Task Scheduler allows you to choose from different triggers, including a specific date, during startup, or when a user signs in to the device. In this case, we’re selecting the option to run a task every month, but you may need to configure additional parameters depending on your requirements.
Use the «Monthly» drop-down menu to pick the months of the year you want to run the task.
Source: Windows Central
Use the «Days» or «On» drop-down menu to confirm the days the task will run.
Source: Windows Central
Select the Start a program option to run the batch file.
Source: Windows Central
Select the batch file you created.
Source: Windows Central
Once you complete the steps, the task will save and run the script on a schedule.
These instructions cover the steps to create a basic task with Task Scheduler. If you want to create a more customizable task, use these instructions.
Run batch files on startup
If you want to execute a sequent of commands every time you sign in to your Windows 10 account, instead of using Task Scheduler, you can place the script in the «startup» folder to save the extra steps.
To run a script on startup on Windows 10, use these easy steps:
- Open File Explorer.
- Browse to the folder with the batch file.
- Right-click the batch file and select the Copy option.
- Use the Windows key + R keyboard shortcut to open the Run command.
Type the following command:
Source: Windows Central
Click the Paste option from the «Home» tab in the Startup folder. (Or Click the Paste shortcut button to create a shortcut to the batch file.)
Source: Windows Central
After you complete the steps, every time you sign in to Windows 10, the batch file will execute and run the included commands.
We’re focusing this guide on Windows 10, but the ability to run batch files has been around for a long time, which means that you can refer to these instructions if you are still on an older version, including Windows 8.1 or Windows 7.
More Windows 10 resources
For more helpful articles, coverage, and answers to common questions about Windows 10, visit the following resources:
The Dell XPS 15 is our choice for best 15-inch laptop
For a lot of people, a 15-inch laptop is a perfect size that offers enough screen for multitasking, and in a lot of cases, some extra performance from powerful hardware. We’ve rounded up the best of the best at this size.
Halo: MCC’s live service elements make it better, not worse
Halo: The Master Chief Collection is more popular than ever, but some fans don’t agree with the live service approach 343 Industries has taken with it. Here’s why those elements are, at the end of the day, great for the game and for Halo overall.
Microsoft’s Surface Duo is not ‘failing up’
Microsoft announced this week that it was expanding Surface Duo availability to nine new commercial markets. While Surface Duo is undoubtedly a work in progress, this is not a sign of a disaster. It’s also doesn’t mean that Surface Duo is selling a ton either. Instead, the reason for the expansion is a lot more straightforward.
These are the best PC sticks when you’re on the move
Instant computer — just add a screen. That’s the general idea behind the ultra-portable PC, but it can be hard to know which one you want. Relax, we have you covered!