I am trying to write a batch file to run several WORD and POWERPOINT file as below:
"C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Literature\Literature Review\Literature-Review.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Literature\Literature Review\outline.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Literature\Questions to be asked\Questions to be asked.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Presaentationen\1. Gruppemeeting\ToDo.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.exe" "D:\Files\Presaentationen\1. Gruppemeeting\Presentation_Englisch.pptx"
The problem is that only the first file opens. If I close it the next one opens and so on. But I want to open them all at the same time. What should I do? (OS is Windows 7)
Thank you very much.
"C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "filename1" "filename2" ...
should open each file in winword.
If you wish to open powerpoint as well, you'd need to start each executable
start "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "filename1" "filename2" ...
start "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.exe "filename3"
but you would need to add the /w switch to the last executable you start this way, otherwise the commands following will be excuted (which you may not want)
Furthermore, the batch would then proceed when the waited application terminates, so
start "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "filename1" "filename2" ...
start /w "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.exe "filename3"
would wait until powerpoint exits and then proceed, regardless of whether winword is still open.
windowtitle may be empty, but should not be omitted (ie. use "" if you want, but don't leave out this element)
When cmd runs a GUI application it does not wait for it to complete. (Whether an application is windowed (GUI) or console is determined by a flag in its exe file.)
But you can use
start /wait SomeGuiApp
to force cmd to wait.
However you appear to have the oposite problem: it could be that &. It is designed for conditionally performing one action dependent on the return value from the previous. But return values are not really meaningful for GUI apps.
Why not run them as separate commands: on different lines of the cmd script or separated (IIRC) by a semicolon.
Remember, with command extensions on you can use parentheses to have multiple lines under the control of if etc.
Related
Since I cannot locate Native Tools CMD under the Tools menu, I try to manually add it in External Tools. Few questions:
Regardless of what I choose for Command (ARM, x86 or x64 etc.), Command is always C:\Windows\System32\cmd.exe. Why the different CMDs end up having the same path to the native System32's CMD?
Referring to this answer, I should insert /k "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" to the arguments - what is the /k and what is the bat for this argument? Why do I need to pass a path as an argument to the command prompt?
What is Initial Directory?
Why the different CMDs end up having the same path to the native System32's CMD?
The VS2015* CMDs are just cmd.exe with some environment variables already set up for you. so for example instead of typing "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe" to run InstallUtil.exe you will just type InstallUtil and it will work. if you didn't set up the environment variables you will get an error message saying that 'installutil' is not recognized as an internal or external command, operable program or batch file.
what is the /k and what is the bat for this argument? Why do I need to pass a path as an argument to the command prompt?
/k is a parameter for cmd.exe and what it does is run the commands specified by the string that follows (in this case it will execute what's inside "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat" and will carry out).
What is Initial Directory?
Initial directory is used to specify the working directory that your cmd.exe instance will start in
So in the end you'll have something like this for Visual Studio 2015:
The "arguments" for VS2015 is :
/k "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
I took a look at my start menu and right clicked on Developer Command Prompt for VS2015. Copied target %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat""
MSBuild Command Prompt for VS2015
Copied target %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsMSBuildCmd.bat""
https://connect.microsoft.com/VisualStudio/feedback/details/747807/vs2012-x64-native-tools-command-prompt
#echo off
echo copy masterDB file from one directory to another one
copy "C:\dir\dbfile" "C:\dir1\dbfile"
cd c:\lvsdir
call lvsrun.bat
timeout /t 180
start %comspec% /k ""C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
cd C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE
MSTest /testcontainer: C:\testdir\test.dll
I want to do via a batch file to copy a db file from one directory to another one(which executes correct), then should start lvsrun.bat file, which should start lvs server,
and then to open visual studio command prompt in a new window, change directory in opened command prompt to test directory and run test file. Problem occurs when i call lvsrun.bat, and it stucks there. New vs command prompt can't be opened. And having problem with changing directory in opened vs command prompt and run test file. Code above doesn't really work
You've asked two questions here. You should split them up and ask them as two separate SO questions.
Q1. Why is my batch file never getting past call lvsrun.bat?
A1. Because call will not return until the batch file it is calling has exited. If you want to launch lvsrun.bat and continue execution immediately, use start.
copy "C:\dir\dbfile" "C:\dir1\dbfile"
cd c:\lvsdir
start "" "%comspec%" /k lvsrun.bat
Q2. Why doesn't the new command window I launch run my test file?
A2. Your batch file will only control its command window. If you launch another command window, that one is on its own, you can't "send" commands to it. But you could instead run the test in the current window rather than launching another:
:: Use "call" here to run vcvarsall.bat to set up the environment in this process
call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
cd C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE
MSTest /testcontainer: C:\testdir\test.dll
Or you could make a second batch file just for running the test. For example, let's call it runtest.bat, and give it those exact same lines:
call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
cd C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE
MSTest /testcontainer: C:\testdir\test.dll
which would then get called from your original batch file either synchronously:
call runtest.bat
or asynchronously:
start "" "%comspec%" /c runtest.bat
I have a batch file that starts an app with a lot of command-line parameters:
"C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\WebDev.WebServer40.exe" /port:1672 /path:"C:\Code.Net\My App\Iteration 6\REL_6.8.806_PerfEnhanceV\Fusion\Code\CC.Fusion\CC.Fusion.Services" /vpath:"/FusionServices"
The problem is that when I run the batch file, the DOS window stays up until the command completes and I would like it to go away. So I tried using the start command, but placing it in front, like this:
start "C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\WebDev.WebServer40.exe" /port:1672 /path:"C:\Code.Net\My App\Iteration 6\REL_6.8.806_PerfEnhanceV\Fusion\Code\CC.Fusion\CC.Fusion.Services" /vpath:"/FusionServices"
But I get an error stating that Invalid switch - "/port:1672"
I have also tried escaping the double quotes, but I was not successful.
How do I fix that?
An extra pair of rabbits' ears should do the trick.
start "" "C:\Program...
START regards the first quoted parameter as the window-title, unless it's the only parameter - and any switches up until the executable name are regarded as START switches.
I think this other Stack Overflow answer would solve your problem: How do I run a bat file in the background from another bat file?
Basically, you use the /B and /C options:
START /B CMD /C CALL "foo.bat" [args [...]] >NUL 2>&1
When i run this batch file command as a single batch file the second command does not run.However when i run them as individual batch file commands they work fine.
"C:\Program Files\Mozilla Firefox\firefox.exe" -P "america" -no-remote http://hakikahost.com/error.html
"nircmd.exe" win hide process "firefox.exe"
tried creating 1 single batch file which called with a call the two batch files now having separated the batch files command separately like this
call test.bat
call hide.bat
where test.bat contained the first command and hide.bat contained the second command but it still didnt work.What am i doing wrong?
It may be that firefox.exe never returns until you close the window. Try using start to launch the applications, as start will return as soon as the application has launched.
start "" "C:\Program Files\Mozilla Firefox\firefox.exe" -P "america" -no-remote http://hakikahost.com/error.html
start "" "nircmd.exe" win hide process "firefox.exe"
The first command, "C:\Program Files\Mozilla Firefox\firefox.exe" does not return until the Fx session has ended (ie you EXIT from it)
Then there are no Fx executables so the second command can't hide the process that doesn't exist.
Try
START "" "C:\Program Files\Mozilla Firefox\firefox.exe" -P "america" -no-remote http://hakikahost.com error.html
"nircmd.exe" win hide process "firefox.exe"
The only difference is the START "" before the firefox-invocation. Note that the empty-quoted-string is required - you could enter a string between the quotes if you like - this becomes the window title.
I'm trying to replace the programs that run from my startup directory with a batch script. The batch script will simply warn me that the programs are going to run and I can either continue running the script or stop it.
Here's the script as I have written so far:
#echo off
echo You are about to run startup programs!
pause
::load outlook
cmd /k "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /recycle
::load Visual Studio 2008
call "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
Both of these commands will load the first program and wait until I close it to load the second. I want the script to load the processes simultaneously. How do I accomplish this?
Edit: When I use the start command it opens up a new shell with the string that I typed in as the title. The edited script looks like this:
start "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE"
::load Visual Studio 2008
start "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
This works:
#echo off
echo You are about to run startup programs!
pause
::load outlook
start /b "" "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /recycle
::load Visual Studio 2008
start /b "" "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
Use START like this:
START "" "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE"
When your path is enclosed in quotes, START interprets it as the title for the window. Adding the "" makes it see your path as the program to run.
There is the start command that will behave much like if you clicked the files in Explorer.