How to run cmd from cmd

How to run cmd from cmd

How to run cmd from cmd

Starts a new instance of the command interpreter, Cmd.exe. If used without parameters, cmd displays the version and copyright information of the operating system.

Syntax

Parameters

ParameterDescription
/cCarries out the command specified by string and then stops.
/kCarries out the command specified by string and continues.
/sModifies the treatment of string after /c or /k.
/qTurns echo off.
/dDisables execution of AutoRun commands.
/aFormats internal command output to a pipe or a file as American National Standards Institute (ANSI).
/uFormats internal command output to a pipe or a file as Unicode.
/t: < | >Sets the background (b) and foreground (f) colors.
/e:onEnables command extensions.
/e:offDisables commands extensions.
/f:onEnables file and directory name completion.
/f:offDisables file and directory name completion.
/v:onEnables delayed environment variable expansion.
/v:offDisables delayed environment variable expansion.
Specifies the command you want to carry out.
/?Displays help at the command prompt.

The following table lists valid hexadecimal digits that you can use as the values for and :

ValueColor
0Black
1Blue
2Green
3Aqua
4Red
5Purple
6Yellow
7White
8Gray
9Light blue
aLight green
bLight aqua
cLight red
dLight purple
eLight yellow
fBright white

Remarks

If the directory path and files have spaces in their name, they must be enclosed in double quotation marks. For example:

If you specify /c or /k, cmd processes, the remainder of string, and the quotation marks are preserved only if all of the following conditions are met:

You don’t also use /s.

You use exactly one set of quotation marks.

You don’t use any special characters within the quotation marks (for example: & ( ) @ ^ | ).

You use one or more white-space characters within the quotation marks.

The string within quotation marks is the name of an executable file.

If the previous conditions aren’t met, string is processed by examining the first character to verify whether it is an opening quotation mark. If the first character is an opening quotation mark, it is stripped along with the closing quotation mark. Any text following the closing quotation marks is preserved.

If you don’t specify /d in string, Cmd.exe looks for the following registry subkeys:

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun\REG_SZ

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun\REG_EXPAND_SZ

If one or both registry subkeys are present, they’re executed before all other variables.

Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer.

You can disable command extensions for a particular process by using /e:off. You can enable or disable extensions for all cmd command-line options on a computer or user session by setting the following REG_DWORD values:

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\EnableExtensions\REG_DWORD

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions\REG_DWORD

Set the REG_DWORD value to either 0Г—1 (enabled) or 0Г—0 (disabled) in the registry by using Regedit.exe. User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings.

Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer.

When you enable command extensions, the following commands are affected:

assoc

call

chdir (cd)

color

del (erase)

endlocal

for

ftype

goto

if

mkdir (md)

popd

prompt

pushd

set

setlocal

shift

start (also includes changes to external command processes)

If you enable delayed environment variable expansion, you can use the exclamation point character to substitute the value of an environment variable at run time.

File and directory name completion is not enabled by default. You can enable or disable file name completion for a particular process of the cmd command with /f:<on | off>. You can enable or disable file and directory name completion for all processes of the cmd command on a computer or for a user logon session by setting the following REG_DWORD values:

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\CompletionChar\REG_DWORD

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\PathCompletionChar\REG_DWORD

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar\REG_DWORD

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\PathCompletionChar\REG_DWORD

To set the REG_DWORD value, run Regedit.exe and use the hexadecimal value of a control character for a particular function (for example, 0Г—9 is TAB and 0Г—08 is BACKSPACE). User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings.

Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer.

If you enable file and directory name completion by using /f:on, use CTRL+D for directory name completion and CTRL+F for file name completion. To disable a particular completion character in the registry, use the value for white space [0Г—20] because it is not a valid control character.

Pressing CTRL+D or CTRL+F, processes the file and directory name completion. These key combination functions append a wildcard character to string (if one is not present), builds a list of paths that match, and then displays the first matching path.

If none of the paths match, the file and directory name completion function beeps and does not change the display. To move through the list of matching paths, press CTRL+D or CTRL+F repeatedly. To move through the list backwards, press the SHIFT key and CTRL+D or CTRL+F simultaneously. To discard the saved list of matching paths and generate a new list, edit string and press CTRL+D or CTRL+F. If you switch between CTRL+D and CTRL+F, the saved list of matching paths is discarded, and a new list is generated. The only difference between the key combinations CTRL+D and CTRL+F is that CTRL+D only matches directory names and CTRL+F matches both file and directory names. If you use file and directory name completion on any of the built-in directory commands (that is, CD, MD, or RD), directory completion is assumed.

File and directory name completion correctly processes file names that contain white space or special characters if you place quotation marks around the matching path.

If the information that you supply contains spaces, you must use quotation marks around the text (for example, «Computer Name»).

If you process file and directory name completion from within string, any part of the path to the right of the cursor is discarded (at the point in string where the completion was processed).

How to Run Program from CMD (Command Prompt) Windows 10 [MiniTool Tips]

You can run a program or an exe file from Command Prompt. Check how to do it in this tutorial. MiniTool software, not only provides many useful computer solutions, but also provides users many useful computer software like data recovery program, disk partition manager, system backup and restore software, video editor, etc.

If you want to run program from CMD (Command Prompt) on Windows 10, you can check the detailed steps below.

How to Run a Program from CMD in Windows 10

You can only run the applications that are installed in Windows-created folders like Explorer in Command Prompt.

Step 1. Open Command Prompt in Windows 10

At first, you should open Command Prompt application on your Windows 10 computer. You can press Windows + R, type cmd, and press Enter to open normal Command Prompt or press Ctrl + Shift + Enter to open elevated Command Prompt on Windows 10.

Step 2. Run Program from CMD on Windows 10

Next you can type start

command in Command Prompt window, and press Enter to open the target application in CMD. Replace the “program name” with the exact file’s system name of the program but not its shortcut name. For instance: start explorer.

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

The file’s system name of some common programs in Windows are as follows:

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

You can use Windows Run commands to fast access tools and settings on your Windows 10/11 computer. Here’s the list of 30 useful Run commands you should know.

How to Run EXE in CMD on Windows 10

You can follow the instructions below to run an exe file in Command Prompt.

Step 1. Access Command Prompt window

You can follow the same operation above to open Command Prompt in Windows 10.

Step 2. Navigate to the folder of the target program

Next you can type cd command in Command Prompt window, and press Enter to navigate to the folder that contains the target exe application. Replace “file path” with the exact file path of the exe file.

You can find the target program folder and click the address bar at the top of File Explorer window to copy the path of the program folder and paste it after cd command. For example, cd C:\Program Files\Windows Media Player.

Step 3. Run exe from CMD

After you are in the target program folder path, then you can type start after the selected file path in CMD, and press Enter to run the exe file in Command Prompt. Replace “filename.exe” with the target program name, e.g. start wmplayer.exe.

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

Bottom Line

This post introduces how to run a program or exe file from CMD on Windows 10. Hope it helps.

If you need a free data recovery software to recover deleted/lost files from Windows 10 computer or other storage devices, you can try MiniTool Power Data Recovery.

MiniTool Power Data Recovery is a Windows data recovery program that allows you to recover data from PC, external hard drive HDD or SSD, USB drive, SD card, memory card, and more. It is very simple to use and 100% clean.

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

This post introduces the 8 best free word processors for Windows 10/11 that let you easily create, edit, save, and print documents on your PC.

How do you run a command as an administrator from the Windows command line?

I have a small script that performs the build and install process on Windows for a Bazaar repository I’m managing. I’m trying to run the script with elevated, administrative privileges from within the Windows shell (cmd.exe)—just as if I’d right-clicked it and chosen Run as Administrator, but without using any method that requires use of the graphical interface.

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

12 Answers 12

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

Press the start button. In the search box type «cmd», then press Ctrl + Shift + Enter

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

All you have to do is use the runas command to run your program as Administrator (with a caveat).

In my case, this was

Note that you must use Quotation marks, else the runas command will gobble up the switch option to cmd.

Also note that the administrative shell (cmd.exe) starts up in the C:\Windows\System32 folder. This isn’t what I wanted, but it was easy enough to pass in the current path to my installer, and to reference it using an absolute path.

Caveat: Enable the admin account

Using runas this way requires the administrative account to be enabled, which is not the default on Windows 7 or Vista. However, here is a great tutorial on how to enable it, in three different ways:

I myself enabled it by opening Administrative Tools, Local Security Policy, then navigating to Local Policies\Security Options and changing the value of the Accounts: Administrative Account Status policy to Enabled, which is none of the three ways shown in the link.

Batch file to run a command in cmd within a directory

I want to have a batch file(must be placed on desktop) which does the following;

Thank you for the help.

EDIT:

Referring to zb226’s answer below: One more question if you can answer me is how to make that cmd to be run as administrator? will the following work?

START cmd /K «runas /user:administrator & cd C:\activiti-5.9\setup & ant demo.start»

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

6 Answers 6

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

Chain arbitrary commands using & like this:

Thus, in your particular case, put this line in a batch file on your desktop:

You can also use && to chain commands, albeit this will perform error checking and the execution chain will break if one of the commands fails. The behaviour is detailed here.

. didn’t prove the solution was working. So I chose another program (nLite) after making sure that it was not executable anywhere on my system:

And that works just as my original answer already suggested. A Windows version is not given in the question, but I’m using Windows XP, btw.

How to run a command on command prompt startup in Windows

If you want to perform any task at computer startup or based on an event this is very helpful

Back to the question

I have two questions:

I want some specific commands to be executed when I start command prompt.

e.g. cls to clear my command prompt.

I want to execute some commands in a batch file and wait for the user to enter new commands (if any).

e.g. A batch file which will take the user to some specified folder and then wait for the user to rename/delete a file from the command prompt.

How can I do it?

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

6 Answers 6

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

If you want a defined set of commands to run every time you start a command prompt, the best way to achieve that would be to specify an init script in the AutoRun registry value. Create it like this (an expandable string value allows you to use environment variables like %USERPROFILE% ):

Then create a file init.cmd in your profile folder:

To remove these changes, delete the registry key:

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

This is the way to launch 1 command without having to mess about with the registry.

Run multiple commands

You can also use & (and) operator to execute multiple commands.

I found my answer: I should use the /K switch, using which I can enter a new command on the opened command prompt.

E.g. cmd /K cls will open a command prompt for me and clear it. (Answer for question 1)

cmd /K MyBatchFile.bat will start a command prompt, execute the batch file and stay on the command prompt and will not exit. (Answer for question 2).

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

First, you need to press Windows Key + R. In the box that appears, type «regedit» (without the quotes). The Windows Registry Editor should open. Now, locate to HKEY_CURRENT_USER/Software/Microsoft/Command Processor. Once you have clicked on Command Processor on the left side, click Edit on the top bar. Then go to New > String Value in the Edit menu. Rename the String Value that appears to Autorun. Right click on Autorun and select Modify. Under the «Value Data» area, type in the commands you want to run. You can run multiple by typing && between them.

How to run cmd from cmd. Смотреть фото How to run cmd from cmd. Смотреть картинку How to run cmd from cmd. Картинка про How to run cmd from cmd. Фото How to run cmd from cmd

Expanding a bit, here is an alternative for Windows 10 where multiple aliases can be defined and applied to the Command Prompt upon execution.

init.cmd

In the Command Prompt, run:

Done

Now the contents of init.cmd will run for executions of cmd.exe namely from:

After registering these settings just remember to close/open:

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *