Run command on Command Prompt start - windows

Is there a way to run any command (eg: cd D:\test) on Command Prompt start and to have this instance of Command Prompt as a different shortcut/instance.

You can create a shortcut that has a target of e.g.:
%comspec% /k ""C:\Full_Path_to\VsDevCmd.bat""
Where the .bat file is the command(s) that you want to run on startup. This will then leave you with an open command prompt after those commands have executed.
(In case it's not obvious, this is just shamelessly ripped from one of the Developer Command Prompt shortcuts that Visual Studio installs in the Start Menu)
%comspec% is a nice way of getting cmd to execute.
Cmd:
/k : Carries out the command specified by string and continues.

Related

CMD does not return to prompt when calling program at time of cmd call

I want to have a desktop shortcut/icon for a cmd prompt which runs a command when it is opened, but then returns to the prompt
I have something like this
C:\Windows\System32\cmd.exe /k "E:\python-gui.pyw"
When I run this the GUI launches as expected, but the command prompt does not return until the GUI closes.
If instead I open a
cmd
and then run the command
E:\python-gui.pyw
then the command prompt is available even while the gui remains on the screen. i.e. I can execute further commands.
Is there a way I can get this behavior from the first call?
As #KJ writes in the comments, a program which would lock the command window can be launched instead with the run command. Launching with the run command launches the program in its own command window, which prevents the original command window from waiting for the program to complete.
waits for program to exit before returning control:
C:\Windows\System32\cmd.exe /k "E:\my_script.script"
does NOT wait for program to exit before returning control:
C:\Windows\System32\cmd.exe /k start "E:\my_script.script"
Create a new file for example I will name it a.bat
put this in it
E:\python-gui.pyw
Go to the original file and add this command
start a.bat

Run appcmd command from shortcut

Very often I have to make following steps in command line (to identify correct worker process in IIS for debugging):
Run cmd as an administrator
cd %systemroot%\system32\inetsrv
appcmd list wp
I want to make a shortcut on the desktop to do it in one click.
How can I achieve that?
P.S. I tried to specify it like on the picture but it doesn't work, just opens cmd in inetsrv folder
I assume you set up the shortcut to run as admin, so I do not go into details on that.
What is missing in your Target line is the switch to tell cmd.exe that there are strings following which should be interpreted and executed as command. You can chose /C for execute and quit (cmd window disappears) or /K for execute and show prompt (cmd window stays open). So the result would be something like: "%windir%\system32\cmd.exe" /K "appcmd list wp". See cmd.exe /? for details.
GL, HF :)

cannot run 'start' command from makefile in windows

I am using gnu make 3.8.1 (mingw32) in Windows 7 operating system.
I want to run 'start' command from makefile but it is giving some error. my syntax of command is-
start CMD /K http-server ./www -c-1
This command works when manually typed in cmd. It opens a new command prompt which runs the command 'http-server ./www -c-1', hosts the files present in www folder of current directory on port 8080 and shows the logs in the command prompt window it opened.
but in makefile, it doesn't seems to work. My makefile is-
hostx:
start CMD /K http-server ./www -c-1
There is more to the makefile but we only need to focus on this part.
when i type 'make hostx' in cmd it shows the following output.
I am posting my cmd output as complete image so this is more clear
any ideas how i could get it to work? also i don't know what does this error mean.
Only Windows 95/98/ME have a program called start.exe, in other versions of Windows it is an internal command inside cmd.exe.
To use the start command you need to invoke cmd.exe first:
CMD /C start CMD /K http-server ./www -c-1
If http-server is a console program or batch file then you don't need the CMD /K part because Windows will create a new console automatically. CMD /C start http-server ./www -c-1 should be enough.

Run a Command Prompt command from Desktop Shortcut

Is it possible to create a desktop shortcut that, when pressed, will open command prompt and run a pre-defined command?
Create A Shortcut That Opens The Command Prompt & Runs A Command:
Yes! You can create a shortcut to cmd.exe with a command specified after it. Alternatively you could create a batch script, if your goal is just to have a clickable way to run commands.
Steps:
Right click on some empty space in Explorer, and in the context menu go to "New/Shortcut".
When prompted to enter a location put either:
"C:\Windows\System32\cmd.exe /k your-command" This will run the command and keep (/k) the command prompt open after.
or
"C:\Windows\System32\cmd.exe /c your-command" This will run the command and the close (/c) the command prompt.
Notes:
Tested, and working on Windows 8 - Core X86-64 September 12 2014
If you want to have more than one command, place an "&" symbol in between them. For example: "C:\Windows\System32\cmd.exe /k command1 & command2".
Yes, make the shortcut's path
%comspec% /k <command>
where
%comspec% is the environment variable for cmd.exe's full path, equivalent to C:\Windows\System32\cmd.exe on most (if not all) Windows installs
/k keeps the window open after the command has run, this may be replaced with /c if you want the window to close once the command is finished running
<command> is the command you wish to run
The solutions turned out to be very simple.
Open text edit
Write the command, save as .bat.
Double click the file created and the command automatically starts running in command-prompt.
Create new text file on desktop;
Enter desired commands in text file;
Rename extension of text file from ".txt" --> ".bat"
Yes. One option you have is to create a batch file containing the command
cmd -c {your command}
or
cmd -k {your command}
The shortcut will then be to this batch file.
This is an old post but I have issues with coming across posts that have some incorrect information/syntax...
If you wanted to do this with a shorcut icon you could just create a shortcut on your desktop for the cmd.exe application. Then append a /K {your command} to the shorcut path.
So a default shorcut target path may look like "%windir%\system32\cmd.exe", just change it to %windir%\system32\cmd.exe /k {commands}
example: %windir%\system32\cmd.exe /k powercfg -lastwake
In this case i would use /k (keep open) to display results.
Arlen was right about the /k (keep open) and /c (close)
You can open a command prompt and type "cmd /?" to see your options.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
A batch file is kind of overkill for a single command prompt command...
Hope this helps someone else
I tried this, all it did was open a cmd prompt with "cmd -c (my command)"
and didn't actually run it. see below.
C:\windows\System32>cmd -c (powercfg /lastwake)
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\windows\System32>
***Update
I changed my .bat file to read "cmd /k (powercfg /lastwake)" and it worked.
You can also leave out the () and it works too.
You can also create a shortcut on desktop that can run a specific command or even a batch file by just typing the command in "Type the Location of Item" bar in create shortcut wizard
Right click on Desktop.
Enter the command in "Type the Location of Item" bar.
Double click the shortcut to run the command.
Found detailed Instructions here
Using the Drag and Drop method
From the windows search bar type in cmd to pull up the windows bar operation.
When the command line option is shown, right click it and select Open File Location.
The file explorer opens and the shortcut link is highlighted in the folder. If it is not highlighted, then select it.
Hold down the Control key and using the mouse drag the shortcut to the desktop. If you don't see Copy to Desktop while dragging and before dropping, then push down and hold the Control key until you see the message.
Drop the link on the desktop.
Change properties as needed.

Launch new command line and exucte in that shell

This must be a real dumb question. And I cant figure out how.
What I want to do is launch a new command line with some arguments and excute some commands there.
Here is what I have in my .cmd
CMD /k %EnvInstallPath% %wo% %var%
cd /d %wo%\src
When I execute test.cmd, I see that the directory changes to %wo%, but the further cd src is not executed. I need to cd to a directory and execute few other commands.
When you run cmd with /k the console runs the command and then resumes with the prompt. I'm guessing that what you want is to run the command and resume with the next one, so you need to run cmd with /c instead.
put the other commands in a different bat file and
start AFewOtherCommands.bat

Resources