Using the "start" command with parameters passed to the started program - windows

I have a Virtual Machine in Virtual PC 2007.
To start it from the desktop, I have the following command in a batch file:
"c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc "MY-PC" -launch
But that leaves a dos prompt on the host machine until the virtual machine shuts down, and I exit out of the Virtual PC console. That's annoying.
So I changed my command to use the START command, instead:
start "c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc MY-PC -launch
But it chokes on the parameters passed into Virtual PC.
START /? indicates that parameters do indeed go in that location. Has anyone used START to launch a program with multiple command-line arguments?

START has a peculiarity involving double quotes around the first parameter. If the first parameter has double quotes it uses that as the optional TITLE for the new window.
I believe what you want is:
start "" "c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc MY-PC -launch
In other words, give it an empty title before the name of the program to fake it out.

Instead of a batch file, you can create a shortcut on the desktop.
Set the target to:
"c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc "MY-PC" -launch
and you're all set. Since you're not starting up a command prompt to launch it, there will be no DOS Box.

You can use quotes by using the [/D"Path"] use /D only for specifying the path and not the path+program. It appears that all code on the same line that follows goes back to normal meaning you don't need to separate path and file.
start /D "C:\Program Files\Internet Explorer\" IEXPLORE.EXE
or:
start /D "TITLE" "C:\Program Files\Internet Explorer\" IEXPLORE.EXE
will start IE with default web page.
start /D "TITLE" "C:\Program Files\Internet Explorer\" IEXPLORE.EXE www.bing.com
starts with Bing, but does not reset your home page.
/D stands for "directory" and using quotes is OK!
WRONG EXAMPLE:
start /D "TITLE" "C:\Program Files\Internet Explorer\IEXPLORE.EXE"
gives:
ERROR "The current directory is invalid."
/D must only be followed by a directory path. Then space and the batchfile or program you wish to start/run
Tested and works under XP but windows Vista/7/8 may need some adjustments to UAC.
-Mrbios

The spaces are DOSs/CMDs Problems so you should go to the Path via:
cd "c:\program files\Microsoft Virtual PC"
and then simply start VPC via:
start Virtual~1.exe -pc MY-PC -launch
~1 means the first exe with "Virtual" at the beginning. So if there is a "Virtual PC.exe" and a "Virtual PC1.exe" the first would be the Virtual~1.exe and the second Virtual~2.exe and so on.
Or use a VNC-Client like VirtualBox.

None of these answers worked for me.
Instead, I had to use the Call command:
Call "\\Path To Program\Program.exe" <parameters>
I'm not sure this actually waits for completion... the C++ Redistributable I was installing went fast enough that it didn't matter

If you want passing parameter and your .exe file in test folder of c: drive
start "parameter" "C:\test\test1.exe" -pc My Name-PC -launch
If you won't want passing parameter and your .exe file in test folder of c: drive
start "" "C:\test\test1.exe" -pc My Name-PC -launch
If you won't want passing parameter and your .exe file in test folder of H: (Any Other)drive
start "" "H:\test\test1.exe" -pc My Name-PC -launch

The answer in "peculiarity" is correct and directly answers the question. As TimF answered, since the first parameter is in quotes, it is treated as a window title.
Also note that the Virtual PC options are being treated as options to the 'start' command itself, and are not valid for 'start'. This is true for all versions of Windows that have the 'start' command.
This problem with 'start' treating the quoted parameter as a title is even more annoying that just the posted problem. If you run this:
start "some valid command with spaces"
You get a new command prompt window, with the obvious result for a window title.
Even more annoying, this new window doesn't inherit customized font, colors or window size, it's just the default for cmd.exe.

If you must use double quotation mark at any parameter, you can get error "'c:\somepath' is not recognized a an internal or external command, operable program or batch file".
I suggest below solution when using double qoutation mark:
https://stackoverflow.com/a/43467194/3835640

/b parameter
start /b "" "c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc "MY-PC" -launch

have you tried:
start "c:\program files\Microsoft Virtual PC\Virtual PC.exe" "-pc MY-PC -launch"
?

Put the command inside a batch file, and call that with the parameters.
Also, did you try this yet? (Move end quote to encapsulate parameters)
start "c:\program files\Microsoft Virtual PC\Virtual PC.exe -pc MY-PC -launch"

Change The "Virtual PC.exe" to a name without space like "VirtualPC.exe" in the folder.
When you write start "path" with "" the CMD starts a new cmd window with the path as the title.
Change the name to a name without space,write this on Notepad and after this save like Name.cmd or Name.bat:
CD\
CD Program Files
CD Microsoft Virtual PC
start VirtualPC.exe
timeout 2
exit
This command will redirect the CMD to the folder,start the VirualPC.exe,wait 2 seconds and exit.

Related

Start external program with arguments (in Visual Studio - Debug properties)

Is it possible to run program with parameters, like on screenshot (Specifically, I've tried to run CMD with some params):
It gives me an error while I am trying to do that.
You should specify parameters in the Command line arguments box:
The problem might be stemming from the second path in your argument. Try wrapping whatever the C:\Program Fi (it's cut off in the screenshot) path is in quotes.
C:\windows\system32\cmd.exe start /m "" "C:\Program Files(x86)\Path\To\Directory"

Trying to open programs with bat file but always comes back invalid

I am a streamer and I need a few programs to stream. It's annoying to open all of them so I tried putting them in a batch file. I looked up the process and followed it,but every time I run the batch file it comes back invalid.
This is what my batch file looks like:
#echo off
cd C:\Program Files "(x86)\obs-studio\bin\64bit"
start obs64.exe
#echo off
cd "C:\Program Files\HexChat"
start hexchat.exe
#echo off
cd "C:\Program Files (x86)\Nightbot"
start nightbot.exe
exit
Cmd gives me an error saying it cannot find the file. When I put this into cmd by itself it opens the program.
Also is there a way to add applications from chrome to the file?
Open a command prompt window and run from within this window start /? which outputs the help for this command and explaining all options.
Following batch file most likely works:
#echo off
start "" "%ProgramFiles(x86)%\obs-studio\bin\64bit\obs64.exe"
start "" "%ProgramFiles%\HexChat\hexchat.exe"
start "" "%ProgramFiles(x86)%\Nightbot\nightbot.exe"
This batch file starts the three applications with current directory on execution of the batch file being also the current directory for the 3 started applications.
But the following batch file should be used if it is really necessary that each application is started with the application's directory as current directory:
#echo off
start "" /D"%ProgramFiles(x86)%\obs-studio\bin\64bit" obs64.exe
start "" /D"%ProgramFiles%\HexChat" hexchat.exe
start "" /D"%ProgramFiles(x86)%\Nightbot" nightbot.exe
With parameter /D and path of application's folder the Start In directory is set first like when using command CD. So for example hexchat.exe is started with current directory being C:\Program Files\HexChat for this application.
The two double quotes after command START are necessary as this command interprets first double quoted string as title for the process. By using "" an empty title string is explicitly specified resulting in rest of command line being correct interpreted as expected. I suppose those three applications are all GUI applications and not console applications and therefore a real title string being useful on running a console application in an new command process for the console window is not really necessary.
%ProgramFiles% references the predefined environment variable ProgramFiles containing path to standard program files folder for 64-bit applications on 64-bit Windows when batch file is started with 64-bit cmd.exe as default on 64-bit Windows and is replaced by Windows command interpreter before execution of the command line on your Windows computer by C:\Program Files.
%ProgramFiles(x86)% references the predefined environment variable ProgramFiles(x86) containing always path to standard program files folder for 32-bit applications on 64-bit Windows and is replaced by Windows command interpreter before execution of the command line on your Windows computer by C:\Program Files (x86).
It is of course also possible to use the real paths in your computer instead of the environment variable references if this batch file is never shared with other people.
Extra hint:
Run in a command prompt window the command you want to use with /? as parameter to get displayed the help for this command. Other sources for help on commands and predefined environment variables displayed all on running in a command prompt window set are:
SS64.com - A-Z index of the Windows CMD command line
Microsoft's command-line reference
Windows Environment Variables and WOW64 Implementation Details

How to Make a .bat file with arguments

For my work I have to run a string in "run".
I want to make this in a bat file but the arguments are not used but without them the program will not run.
This is the string:
"C:\Program files (x86)\MicroTouch\MT7\TwUI.exe" TwUICP.dll CPMain
Can someone help me with this problem?
You can simply put the same line of code into your bat file:
"C:\Program files (x86)\MicroTouch\MT7\TwUI.exe" TwUICP.dll CPMain
There are some options you can use. For example if you want the program to run hidden in background you can add start /b before the line. start /w will make the cmd window stay open and wait for your program to finish. You can even definde which CPU cores the program should use. For more information open the console and type start /? or check out http://ss64.com/nt/start.html.
Have the same problem, same software i think...
"C:\Program Files (x86)\MicroTouch\MT 7\TwUI.exe" twuicp.dll CPMain
Running that line through task manager -> new task will open a tool to configure touch-screen options, calibrate, etc...
Well same line doesnt work in a bat or cmd file. If i try to launch this tool through cmd.exe it doesnt work either.
The answer is always the same:
USAGE: twui <DLL name> <UI symbol name>
This works, but same line in cmd.exe dont

create a program that can run a cmd prompt

I have a program that changes my desktop wallpaper by dragging the picture file onto it. I also have a wireless network program that can auto open programs everytime it connects to a certain network.
I want to change my desktop everytime it connects to a certain network, but running the wallpaper program doesn't do anything unless I drag the picture onto it. However, I can also run a cmd prompt "c:/program.exe picture.jpg"
I tried creating a batch file START C:/PROGRAM.EXE PICTURE.JPG, but it doesn't work.
So basically I am trying to create a program that can run the cmd prompt "c:/program.exe picture.jpg" - can you help, please?
Remove the "start" from the batch file, and make sure any paths with spaces in them are enclosed in quotes, otherwise they'll be broken into arguments.
For example:
"C:\Program Files\MyProgram.exe" "C:\Documents and Settings\Me\MyPicture.jpg"
A batch job should work. Try skipping that START from your example.
Start - Run - Type :
cmd /c "start /max ""C:\Program Files\MyProgram.exe"" ""C:\Documents and Settings\Me\MyPicture.jpg""" .
The cmd /c - starts a new cmd instance and quits

How to create batch file in Windows using "start" with a path and command with spaces

I need to create a batch file which starts multiple console applications in a Windows .cmd file. This can be done using the start command.
However, the command has a path in it. I also need to pass paramaters which have spaces as well. How to do this?
E.g. batch file
start "c:\path with spaces\app.exe" param1 "param with spaces"
Actually, his example won't work (although at first I thought that it would, too). Based on the help for the Start command, the first parameter is the name of the newly created Command Prompt window, and the second and third should be the path to the application and its parameters, respectively. If you add another "" before path to the app, it should work (at least it did for me). Use something like this:
start "" "c:\path with spaces\app.exe" param1 "param with spaces"
You can change the first argument to be whatever you want the title of the new command prompt to be. If it's a Windows app that is created, then the command prompt won't be displayed, and the title won't matter.
Escaping the path with apostrophes is correct, but the start command takes a parameter containing the title of the new window. This parameter is detected by the surrounding apostrophes, so your application is not executed.
Try something like this:
start "Dummy Title" "c:\path with spaces\app.exe" param1 "param with spaces"
start "" "c:\path with spaces\app.exe" "C:\path parameter\param.exe"
When I used above suggestion, I've got:
'c:\path' is not recognized a an internal or external command, operable program or batch file.
I think second qoutation mark prevent command to run. After some search below solution save my day:
start "" CALL "c:\path with spaces\app.exe" "C:\path parameter\param.exe"
Interestingly, it seems that in Windows Embedded Compact 7, you cannot specify a title string. The first parameter has to be the command or program.
You are to use something like this:
start /d C:\Windows\System32\calc.exe
start /d "C:\Program Files\Mozilla
Firefox" firefox.exe start /d
"C:\Program Files\Microsoft
Office\Office12" EXCEL.EXE
Also I advice you to use special batch files editor - Dr.Batcher
Surrounding the path and the argument with spaces inside quotes as in your example should do. The command may need to handle the quotes when the parameters are passed to it, but it usually is not a big deal.
I researched successfully and it is working fine for me. My requirement is to sent an email using vbscript which needs to be call from a batch file in windows. Here is the exact command I am using with no errors.
START C:\Windows\System32\cscript.exe "C:\Documents and Settings\akapoor\Desktop\Mail.vbs"

Resources