Run the text file via the command line. How to run a program from the command line: three easy ways. Search by extension

Perhaps nothing affects the security of a system more than the user of the system itself, and sometimes administrators have to fight not so much with enemy Trojans as with a simple user. For these purposes, accounts with certain rights are used; created a group, assigned rules, added users and that’s it – let them enjoy the Start button and the scarf.

The same situation is with the Internet, if you surf as an admin on the worldwide grid, then no matter how, there will be an evil virus that will penetrate the system and want to run the program from command line for further dirty tricks, and for control, it will be registered in the registry. Another thing is a limited account - you can’t do much with it. But even in this case, you have to make exceptions - for example, you need to run the program through the command line not under your own account, and under another (with greater rights) or simply launch programs with additional parameters. For these purposes, two command line utilities will be considered - RUNAS(running a program via the command line under a different account without logging out) and START(run the program from the command line with additional parameters). We remember that to fulfill similar actions The script server provides methods and .

START utility - command line

This utility provides a number of additional parameters:

  • launching programs in a certain mode;
  • open a browsing window for a given directory (folder);
  • open documents whose type is registered in Windows (that is, it is specified which application should open a document with a given extension).

And so, let's get acquainted with the basic syntax of this utility:

START ["header"] [command/program] [parameters]

Provided that the command/program defines an internal command line command ( DIR, COPY…) or batch file, then to launch them in a new window (provided that the key is not specified /IN) the program starts automatically CMD.EXE from the command line with the switch /K. Under this condition, the new window will not be closed after the command is executed. Provided that it is not an internal CMD utility or a batch file that is being executed, then this program runs in a graphical or text window.

Provided that the first element shell will be the word CMD without extension and file path, then the command processor will replace it with the value of the variable COMSPEC(full path to the command interpreter). If the first element is the name of the program being executed without an extension, then the value will be used environment variable RATNECHT, this will make it possible to determine the name extensions of executable Files and the search order for the desired file. Typically, the RATNEXT variable contains the following values:

RATNEXT=.COM;.EXE;.BAT;.CMD

Provided that no file with the default extensions is found, the command interpreter will check whether the given name directory name. If so, then START utility will launch Explorer and open the specified directory in it.

"heading"– defines the title the window being created. For example:

START "Copying data" copyier.bat

/paththis parameter specifies the working directory when opening a new command window.

/Igiven key says it's new operating environment will be the original environment passed by cmd.exe, not the current command window environment.

/MIN– this parameter says that the command/program is launched via the command line in a minimized form, but if /MAX is used, then in a maximized (maximized) window.

/SEPARATE– execution of a 16-bit application in a separate memory area

/SHARED- execution of a 16-bit application in general area memory

Keys /LOW | /NORMAL | /HIGH | /REALTIME| /ABOVENORMAL | /BELOWNORMAL set the priority of the task to be launched.

/WAIT– run the program from the command line and wait for it to finish

/IN- execution occurs without creating a new window (of course, if this is possible). Thus, if this key starts internal team cmd.exe or batch file then new copy command interpreter will be launched in the current command window.

Examples of using the START utility:

Need to run from a command prompt window as the main process Microsoft Word with automatic opening of two specified files(the name of one of the files contains a space, so it is in quotes):

START /MAX winword.exe "My document.doc" docum.doc

Opening a browser window for the My Documents directory on the current drive:

START "My documents"

Opening a browser window for the current directory:

Opening the My Favorite Document.doc file from the My Documents folder in a standard window:

START "C:\My Documents\My Favorite Document.doc"

RUNAS command line utility

RUNAS utility The command line does not contain complex syntax, and is quite simple to use. It allows you to run a program via the command line as another user without terminating the current session. As a rule, it is used by administrators to perform small tasks. system commands. For example:

runas/user: [email protected] regedit.com

runas /user:dataAdmin regedit.exe

Naturally, if you need to run an application under another user who has more authority and has a password, then of course you need to know the password, there’s no way without it:

runas/user: [email protected] regedit.exe
Enter password for [email protected]:
Attempting to start “regedit.exe” as user
"[email protected]"...

Command in Command Prompt Window Runas/? provides detailed help on additional options for this utility.

Dear friends, it's no secret that users working on Linux based, always turn up their noses at those who work on Windows. They say that for Windows you need to install the application for at least 10 minutes by clicking a large number of buttons, fiddling with the selection checkboxes. And before you actually install the application, you need to find the official website of the program without getting lost on the Internet. Linux users are proud that they can install any utility from the terminal by executing a certain command.

In Windows it is available as in Linux opportunity installing, uninstalling or editing programs using commands.

The developers claim that Windows 10 will also have the ability to quick installation, updates and deletions various support from the system terminal. We just have to wait for the official release. But you don’t have to wait for the release, but use it right now amazing feature, which will allow the user to install the program from the command line. However, this is not all the surprises: the utility will also allow you to delete, update, open and close the program. Interesting? Let's get to know Chocolatey better.

Installing the program via the command line

Now we will try to manage programs in a more convenient and very similar way to how it is done in Linux environment. And it will help us with this special service Chocolatey, package manager for Windows. The Chocolatey client is a utility designed to run in the console. Let's try to install it right away. To install, open a terminal with administrator rights. Click right click mouse on the Start menu and click “Command Prompt” (with administrator rights). Now let's copy the following code:

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE% \chocolatey\bin

Insert and press Enter key. Now you need to close the console so that the data on the variables is refreshed.

The Chocolatey service has a large catalog of utilities and applications: this moment more than 2000 utilities. You can view them on the official website https://chocolatey.org/packages. So, it's time to learn how to install any program via the command line:

Open the terminal again as administrator. We copy the text presented to the right of the program on the website https://chocolatey.org/packages. For example, to install a browser Google Chrome the following code is presented:

choco install googlechrome -y

Copy it and paste it into the terminal. Don’t forget to write the combination -y after the code from the site. Press Enter. Now all that remains is to wait for the browser installation to complete. After which you can close the terminal window.

As you might have noticed, Google browser Chrome installed very quickly. We didn't have to click any buttons or select a location to save the files (disk C is used by default). By the way, novice users can make a set of their favorite applications in a notepad, so as not to go to the Chocolatey service every time. To uninstall a program via the command line, enter the code uninstall, then the name of the program. For example, choco unistall ccleaner.

ATTENTION. The service only works with packages that are installed through it. That is, if any software is not available for installation through Chocolatey, then you will not be able to remove it this way.

How to run or uninstall a program via the command line

Now let's look at a method that allows through the command line. This can be done in three very simple steps. Let's get started:

  1. Opening the operating terminal Windows systems.
  2. In the window that appears, write the full path to the location of the application launch file. For example, D:/Files/chrome.exe
  3. We press Enter and wait for the system to open what we need.

It's time to learn how to close a program via the command line. For this we need additional security taskkill. Let's start:


Let's sum it up

Dear readers, today we examined what seemed, at first glance, to be a complex topic. But now you know that you can very easily install or uninstall some programs through the command line using the Chocolatey service. And you also know how to open or close an application through the same terminal. We hope that you managed to do everything correctly and that there are no questions left on the topic. Tell us your opinion and impressions in the comments!

Most users of the Windows operating system are accustomed to launching the desired application or game double click by a shortcut located on the desktop, or by finding it in Start. Alternatively, you can open the folder in which it is installed and run the exe file from there.

Since launching applications this way may not always be suitable, in this article let's look at a few in various ways, using which you can run the program from the command line.

Method 1: launch the system application

In order to run one of the following from the console system applications The “start” command is used and the desired name is indicated separated by a space. You need to enter the system name as the name. For Explorer - this is explorer, task manager - taskmgr, control panel - control, system configuration - msconfig.

To open notepad write notepad , player Windows Media– wmplayer, Paint – mspaint, symbol table – charmap. If you type cmd , a new command prompt window will open.

For example, let's open the symbol table. Type in the line:

and press "Enter".

Method 2: specifying the full path to the file

If you need to run any other installed application, then you should specify the full path to the program executable file.

For example, in my Downloads folder there is a program for installing Film Studio, let's open it. I go into the folder and click on the field where the path is written. This entire line needs to be written on the command line (since copy-paste does not work there) and at the end add the name of the utility that we want to run.

The console will write:

c:\users\master\downloads\wlsetup-all

After pressing “Enter”, preparations for installing the Film Studio began. As you can see, specifying the path is not necessary to use capital letters, you can enter only small ones.

If there are spaces in the path to the desired file, then a window will appear with a message that the specified file cannot be found. The problem is that the command line recognizes the path up to the first space, not the entire line you entered. In the example, it decided that I wanted to open c:\program .

Now let's move a little away from the topic and look at how to find out the full path to the program that we want to run.

To do this, find through the Explorer window executable file desired application. To understand that this is it, make sure that “Application” is indicated opposite it in the “Type” field. Then click on the field at the top - this is the path.

For example, Total Commander is launched by the file “totalcmd”, and it is located along the path: "c:\program files\total commander".

Or another option. If there is a shortcut to the desired application on the desktop, you don’t have to search for it through Explorer. Just right-click on it and select "File location".

The window we have already looked at will open. It will highlight the file that launches the utility, and at the top you can find out the path to it.

Method 3: using path

Using this command, we will save the path to the folder in which the executable file is located, and then run it.

Let's consider the same Total Commander. In the console we write:

path c:\program files\total commander

Be sure to include a space after “path”. It is along this path that the “totalcmd” file we need is located. Press "Enter".

The specified program will be launched. It is not necessary to specify the extension at the end. Thus, you can run any executable file in the specified folder.

Method 4: using the cd command

This command will open the specified folder, and from it we will launch the file we need. For example, let's go to the TeamViewer folder:

cd c:\program files\teamviewer

After "cd" put a space. Press "Enter".

This folder contains the file that launches TeamViewer; it has the same name. So next I enter:

I press “Enter” and the utility starts.

If you need to open an application that is not installed on system disk, then you can use the path command. If I type:

path d:\program files\ccleaner

(after entering each line, press “Enter”), then CCleaner will open. It is installed in the specified path on drive D:.

But this cannot be done using the cd command.

Method 5: through the context menu

To do this, find the folder in which the executable file is stored and right-click on it, while holding down the Shift key. Next, in the context menu, select "Open command window".

After this, the folder we need will immediately open in the command line. Enter the name of the file that runs the utility in the line and press Enter. We launched CCleaner, which is not located on the system drive (I have D:).

If you need to run a program that is installed in the same place as the operating system, the steps are the same. Let's open the Google Chrome browser. We find the folder in which the file is stored that launches it, and select the item mentioned above.

Then enter the name of the file with the extension .*exe: chrome, and press “Enter”. The browser will be launched.

Method 6: path in quotes

At the beginning, I mentioned that if there are spaces in the specified path, the file will not open. But if you write it in quotes, the console will understand everything. Quotes must be double and straight, not commas. They are installed using the combination “Shift + E” with the selected English keyboard layout.

In them you need to write the full path and at the end indicate the file itself with the extension that will be launched:

"c:\program files\total commander\totalcmd.exe"

Absolutely all programs can be launched from the command line. This feature appeared in the first operating systems, including the line of systems Microsoft Windows. Previously, operating windows were a continuous command line ( MS-DOS system). Today, many program developers include in their distribution the ability to run as a single file using the command line.

You will need

  • Operating system command line (cmd.exe).

Instructions

  • To simply launch the program from the command line, you need to do the following:
  • Click the "Start" menu - select "All Programs" - "Accessories" - "Command Prompt";

    In the window that opens, you need to return to drive “C”; to do this, at the end of the line, enter “cd..” and press Enter. Repeat this action several times until you completely move to the “C” drive;

    Enter the full path to the program you are running (C:\Program Files\KeyTweak\KeyTweak.exe).

  • You can also run the program with various parameters. These options are in addition to the actions performed by the program itself. Additional parameters look like an addition to the main program launch line.
  • The command line with additional parameters might look like this: “C:\Program Files\KeyTweak\KeyTweak.exe” u -r –y.
  • C:\Program Files\KeyTweak\KeyTweak.exe - full path to the Key Tweak program. Parameters used in this example Key programs Tweak:

    - "u" – quick start programs;

    - “-r” - restore the last saved changes;

    - “-y” - answer “Yes” to requests received from the system.

  • In order to create a cmd file you need to:
  • Create new Text Document with extension .txt.

    Write down necessary set commands

    After completing these steps, run the file.

    Indispensable in case of computer failures. Getting started with skills usually involves working on how to open, copy, run, delete a file. You can see below what the algorithm of actions will look like for each of the components of the work. Let's start with the question of how to open a file via the command line, then we'll show you how to delete them and copy a piece of text. A beginner can handle these tasks, but for those who have been working with a computer for a long time, it is useful to remember or study these options for carrying out common processes.

    In the team Windows line You can fully work with files.

    Sometimes you can’t open files through Manager or Explorer, then the command line will help you. You just need to remember a few commands.

    So, you have launched the program and want to open one of the documents. Follow this algorithm.


    Subsequently, having remembered the path, in order to launch it, you will not need to go to the directory; you just need to enter the full path right away in the line.

    ADVICE. To make work faster, there are bat files; commands that are needed and often typed are written into them in advance. Then this file is launched, and it will open the desired program.

    Launching and closing programs

    Let's look at how to run a file from the command line if it is a program file. What will matter here is whether the application is included in Windows package or did you need third party application. If the application you are opening is part of Windows components, launch is done by entering its name into the console, then pressing Enter. The extension is not required. Let's say you need to launch Notepad, then just type the word notepad and then press Enter.

    If the program is third-party, you should enter the full path to it. For example, you needed to launch WinRAR archiver, then you enter the following:

    C:\Program Files\WinRAR\WinRAR.exe

    Write the path in quotes if the address contains spaces. In this case, quotation marks are needed straight - not in the form of commas. If the quotes are incorrect, the program will not open. You do not need to copy the quotes; you type them directly into the command line, without using the clipboard. On English layout the necessary quotes are in combination Shift keys+ E.

    ADVICE. If you go to the directory with the program, you do not need to enter the full path to it. Simply enter the file name with extension. For example, going to the WinRAR directory, enter the command WinRAR.exe - the program will launch.

    To close applications, use the taskkill program. First, type tasklist, a list of processes will appear for your viewing. Enter the indicator number in the command, for example “taskkill /pid 3900/f”, press Enter to confirm. 3900 is the ID number.

    Search by extension

    The command line will help you find required file by its extension, if you don’t remember its exact name. To find a file via the command line, you need to remember the command used in this case. Type dir and the extension you need separated by an asterisk. Let's say you are looking for one of the executable files, so you type:

    All files with this extension will be displayed on the screen, you just have to find the one you need among them. If you need to search in subdirectories, add the “/S” switch. Full team to search for a file in drive C, including searching in subdirectories, would look like this:

    Removal

    Remove unnecessary ones system files It is also possible through the program in question. Deleting a file via the command line is easy. To delete, use the del command. After it, the path to the required document is written. For example, you want to delete 123.txt. Enter the following: “del C:\Windows\123.txt”.

    IMPORTANT. To completely clear a folder, use the “/S” attribute. With this key you can delete any nested directories and all data.

    Copy text

    OS Windows, taking care of speeding up and making work on a PC easier, has created hot keys - combinations that allow you to quickly copy text and paste it into another file. These are the combinations Ctrl+V or Shift+Insert.

    This doesn't work on the command line. To copy information in it, you must first configure it.


    Now, to copy a piece of text from the command line, select it with the mouse and press Ctrl+C.

    All these skills will be useful to you if you cannot complete required process in the usual way due to failures or computer problems. Simple steps, an easy-to-remember algorithm, clear instructions - everything helps you solve the questions posed more professionally. You just need to remember the list of commands, follow the rules for entering them (for example, when to put quotes and which ones), clearly and accurately enter the path to the required file.