I am on windows 10 and i need to run multiple executable files from a batch file silently, without waiting for them to finish. at the moment i have:
#echo off
start "" "%~dp0executable.exe" /q
start "" "%~dp0executable2.exe" /q
but this still opens multiple console windows.
any workarounds that achieve the same results are welcome.
Your executables seem to be console applications, otherwise no console window would appear.
Anyway, the start command features an option /B; here is an excerpt of the output of start /?:
B Start application without creating a new window. The
application has ^C handling ignored. Unless the application
enables ^C processing, ^Break is the only way to interrupt
the application.
By ^C and ^Break, pressing Ctrl + C and Ctrl + Pause/Break is meant, respectively.
In case you have a third .exe that needs to wait after the first two started simultaneously you can also use the start /w argument for the second one and call the third like so:
#echo off
start /B "%~dp0executable.exe"
start /W "%~dp0executable2.exe"
call "%~dp0executable3.exe"
Related
I'm trying to run a batch file that will close a different cmd window. I know I can do this:
TASKKILL /IM "myapplication.exe" /F
But whilst this does (obviously) kill the task, it doesn't close the cmd window myapplication.exe was running in. I cannot edit myapplication.exe or I would put an 'exit' on the last line.
Any help would be much appreciated.
Well, if your program was started from cmd, then obviously cmd is still running even if you kill or exit that application. To kill cmd as well you can apply the same command to a different program (in a quite obvious way).
However, this will also stop your batch file for equally obvious reasons.
Is there a particular need to run myapplication from cmd?
I have a batch file to run an application (I used to write some basic code in the 80s in DOS), and I need it to "re-execute" the application every x hours. The thing I cannot find is how to "close" (or stop) the application before running the code again, so it wont keep opening several cmd.exe windows with every loop. I am a total noob at coding but I know the principles of batch files
My actual .bat looks like this
setx some-minor-adjustments
application.exe -couple-of-variables
Then, it opens the usual cmd.exe window, and keeps running the application forever. What I need to do is, somehow, "refresh" (close and re-execute) the application automatically every x hours.
Closing the cmd.exe window is just fine to close the application, nothing more is needed in that sense (like data to save for example)
A friend suggested the cron command but it seems to be for other purposes. I also find over the Internet that I should use the start command to open the application in a new cmd.exe window, or something like that
Any ideas? Thanks in advance!
On Windows, the Task Scheduler is used instead of CRON.
Tasks in task scheduler can be set to shut down after a set time if you can be sure of the maximum duration.
You can also add an exit command after the main command if the main command can be assumed to finish (or spawns to a separate process).
:BEGIN
start /b mspaint
ping -n 6 localhost
tskill mspaint
GOTO BEGIN
This should work on all versions of Windows. Just keep in mind that you have to change the number 6 to the number of seconds of delay you want plus one i.e., the above ping statement will produce a delay of 5 seconds. Similarly, to produce a delay of 1 hour, you will have to write
ping -n 3601 localhost
Also make sure that the batch file is in the same folder as your executable otherwise you will have to specify full path.
Note: You can use mspaint.exe in the start command but for the tskill command, parameter should be only mspaint(no extensions). Using #echo off won't be of much help in this case as the ping requests are echoed back and can't be turned off. You can instead use a batch-to-exe converter and create a silent windowless executable. The -n parameter of ping can be very large but has to be in seconds.
[Context: I'm trying to create a shortcut to a .bat file with a relative "Start in" path as roughly described here and here.]
cmd.exe supports the /c switch. According to the documentation, this should cause it to "carry out the command and then terminate."
But the switch seems to be ignored when the command is a .bat file.
For example, if you create a shortcut with the following Target (to a normal, non-bat command):
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ notepad.exe test.txt"
Everything works as expected: Notepad opens and the console (shell) disappears. But if you replace the command above with a .bat file instead, like so:
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ C:\test.bat"
(where test.bat contains only "notepad.exe test.txt") Notepad opens as before but the console sticks around like an unwanted friend. Why? And more to the point, How do I make it go away?
UPDATE: I know I can use wscript, as in this solution, but then I lose the option of having a custom icon (I'm stuck with the default .vbs icon).
The start command begins a new process for the batch file. The original cmd.exe then terminates, but leaves the new process, which hangs around because it's waiting for notepad.exe to terminate.
Change your bat file contents to:
start "" notepad.exe test.txt
Then your batch file will not wait for notepad to exit before continuing execution.
Another thing to try:
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ C:\test.bat & exit"
The nuclear option would be to write a small program in the (compiled) language of your choice that launches the .bat file and then exits. Then you can give it a custom icon, and make it do whatever you like.
You might also take a look at Autoit from http://autoitscript.com as an alternative to batch. - the Run() command can do this kind of thing with better predictability. Since it makes an executable you can link this from a shortcut directly. You can also do a whole lot more of course, like run as a different user, insert delays or handle errors, that are hard to do with batch.
You don't need the full kit, just the Aut2EXE folder from the download will do.
BTW, build your exes without UPX compression as that leads to AV false positives.
I'm a little late but here is the answer.
The documentation for start states:
Syntax
START "title" [/D path] [options] "command" [parameters]
If command is an internal cmd command or a batch file then the command
processor is run with the /K switch to cmd.exe. This means that the
window will remain after the command has been run.
If start is used to execute a batch file, the opened cmd instance wont close.
You could also use call instead.
call C:\test.bat
I like to portable-ise as many programs / apps as I can, so I regularly create self-executing SFX archives that extract to %temp% and then run a selected file (usually the original .exe or, if necessary, a .bat file).
I'm trying to combine a x86 and x64 version of an app into one version, as I don't like having 2 files. So, I have 2 folders ("x86" and "x64") containing the different versions of the program and a .bat file in the root that will check the user's bitness and then launch the appropriate version. I'm having a few issues, though.
Here is my code:
checkandrun.bat
#echo off
goto Payload
:Payload
echo Checking architecture bit-type...
IF EXIST "%systemRoot%\SysWOW64" (
echo Your version of Windows is 64-bit [x64]
start "x64\GCFScape.exe" >nul
) ELSE (
echo Your version of Windows is 32-bit [x86]
start "x86\GCFScape.exe" >nul
)
echo.
echo Starting the appropriate version...
goto End
:End
echo.
echo This window will close in 20 seconds.
ping localhost -n 21 >nul
exit
If I use start then the original command window will exit correctly, as desired, but will open up a new, constant command window and the app won't launch.
If I don't use start the app will launch but the command window will stay open and won't progress past the line of code that was used to launch the .exe. If I close the app itself then the command window will proceed as normal to the exit command and close successfully.
Is there is a way around this? I've never had this kind of problem before.
Here is a link to the SFX archive in my Dropbox, if anyone wants to take an actual look at the environment and effects for themselves: https://dl.dropbox.com/u/27573003/Social%20Distribution/gcfscape182.exe
The docs for the START command say that the first arg that is in quote marks will be the title of the window. So, try this:
start /B "GCFScape" "x64\GCFScape.exe">nul
Is there any way to execute an application without waiting in batch file? I have tried the start command but it just creates a new command window.
I'm making a guess here, but your start invocation probably looks like this:
start "\Foo\Bar\Path with spaces in it\program.exe"
This will open a new console window, using “\Foo\Bar\Path with spaces in it\program.exe” as its title.
If you use start with something that is (or needs to be) surrounded by quotes, you need to put empty quotes as the first argument:
start "" "\Foo\Bar\Path with spaces in it\program.exe"
This is because start interprets the first quoted argument it finds as the window title for a new console window.
I used start /b for this instead of just start and it ran without a window for each command, so there was no waiting.
If your exe takes arguments,
start MyApp.exe -arg1 -arg2
If start can't find what it's looking for, it does what you describe.
Since what you're doing should work, it's very likely you're leaving out some quotes (or putting extras in).
EDIT moved /B parameter/switch to before the command path, as per Nime Cloud's recommendation
I successfully used a combo of #joey's post, with added /B flag, as follows
START "" /B "Path\To\Application.exe"
Partial output from help command: HELP START...
B Start application without creating a new window. The
application has ^C handling ignored. Unless the application
enables ^C processing, ^Break is the only way to interrupt
the application.
This command starts ClamAV in a seperate console window with custom icon of clamd.exe
start "c:\clamav\clamd.exe" "c:\clamav\clamd.exe"
So the generic format would be like:
start "Your new title" "c:\path\your.exe"