Commands in BAT files are not processed - windows

#ECHO OFF
title Skype secondary Instance
echo A second instance of Skype will be started.
pause
"C:\Program Files\Skype\Phone\Skype.exe" /secondary
exit
After running this BAT script the command windows does not close until the Skype program is not closed. Could you tell me why? And how to close the command window after the program has started.

Use the START command.
start "" "C:\Program Files\Skype\Phone\Skype.exe" /secondary
Although, I should think you don't even need a batch file. You could simply create a shortcut with "C:\Program Files\Skype\Phone\Skype.exe" /secondary as the target.

Related

Keep cmd.exe console window with specific title open?

in Windows 7 x64 SP1 I need to create a batch file (.bat) which keeps the cmd.exe console window open and has a specific title:
#ECHO OFF
title notepadtest
#ECHO ON
start "" /WAIT notepad
But this batch file keeps opening an infinite number of cmd.exe console windows in an unstoppable loop!
How can I create a batch file (.bat) which creates only ONE cmd.exe console window and keeps it open and has a specific title?
Please ensure that your batchfile is not named notepad.cmd or notepad.bat or anything like any system or external command. Name it something like mynotepad.cmd instead., then try this one please:
#echo off
title notepadtest
start "" /w notepad.exe
cmdline and batch files typically works like this. When a command is issued, it first checks the local path, where the script was launched from for the command, if not found, it will check your environment and system environment. So if you name a batchfile notepad.bat your batch is actually starting itself over and over, instead of finding notepad.exe in the environment variables.
Always name batch files something unique and not system/external command related.
Always use full executable name in a batch, like start "" /w notepad.exe and not start "" /w notepad

How to use a .bat file to run other .bat(s) and have each one in a seperate cmd prompt in different directory locations

start cmd
cd /d C:\U\O\D\L\D\M
call runbot.bat
cd /d C:\U\O\D\L\F
call RunBossBot.bat
My issue is switching between cmd windows, it attempts to put everything in one window.
Grateful for any help,
Thanks
start "" "c:\somewhere\runbot.bat"
start "" "c:\somewhere\RunBossBot.bat"
Starting a Program
See start /? and call /? for help on all three ways.
Specify a program name
c:\windows\notepad.exe
In a batch file the batch will wait for the program to exit. When
typed the command prompt does not wait for graphical
programs to exit.
If the program is a batch file control is transferred and the rest of the calling batch file is not executed.
Use Start command
start "" c:\windows\notepad.exe
Start starts a program and does not wait. Console programs start in a new window. Using the /b switch forces console programs into the same window, which negates the main purpose of Start.
Start uses the Windows graphical shell - same as typing in WinKey + R (Run dialog). Try
start shell:cache
Use Call command
Call is used to start batch files and wait for them to exit and continue the current batch file.

Windows 8.1 unable to run batch file without command prompt flashing

I have scheduled a task to run a batch file, and currently every time the task executes, there is a command prompt box that flashes. This is very undesirable. The node.js command prompt window executes minimized correctly, it is the windows command prompt that flashes.
Here is the action that the scheduled task runs:
cmd /min /c "C:\Users\computeruser\Building Intelligence\javadobe\runCheck.bat"
and here is the contents of the batch file, (probably unnecessary to show, but I was originally trying to run these commands straight from the task scheduler. Putting them in this batch file instead has got me closest to what I actually want to happen: run a javascript file with node.js minimized):
cd "C:\Program Files (x86)\BuildingIntelligence\javadobe\" & START /MIN node index.js /exit
A list of the commands I've tried:
cmd.exe /c start /min "C:\Users\computeruser\Building Intelligence\javadobe\runCheck.bat"
cmd.exe /c start /min "C:\Users\computeruser\Building Intelligence\javadobe\runCheck.bat" & /exit
%comspec% /c start "" /min "C:\Users\computeruser\Building Intelligence\javadobe\runCheck.bat"
all of these commands leave the command prompt box open, not closing it but minimizing it after it opens. There is also a notification that says "not enough storage is available to process this command".
I need to run this task with the highest privileges, and while it needs to be invisible most of the time, it needs to be able to show a dialog box occasionally when the task is run.
Thanks in advance for any help!
Basically, if what you have tried doesn't work, you're going to need a third party tool. NirCMD should do it and it's freeware.
NirCMD exec hide "C:\Users\computeruser\Building Intelligence\javadobe\runCheck.bat"
At the bottom of this page there is a link for the download. This page covers what the tool is capable of.

Running Several batch Commands in Sequence

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.

How do I run a .exe but stay in the same command window (not open a new one)?

I have searched for many weeks to solve my problem and can't find a good way of doing it that works on every machine I may need to use.
I know START command opens a new window to do the .exe, but I want to stay in the same window and run the .exe
(because I want my batch file to continue ONLY WHEN THE .EXE has finished running)
I have found that on some computers when I .exe it opens a new window and other computers is stays in the same window which makes me think my code is fine but there is a setting somewhere on the computers that is different.
Can you help? What are my options? The .exe I am running is NASTRAN which is an engineering solver that runs in command window.
To wait for the command to terminate you should use the WAIT flag:
start /WAIT c:/windows/system32/notepad.exe
You could start an application without creating a new window using the B flag:
start /WAIT /B "c:/windows/system32/cmd.exe"
You should also try reading the help text for the start command:
start /?
You can use cmd /k example.exe
You probably have a different variant of the .exe on some machines which is called only there, and spawns a separate window, for reasons I cannot know. Search for the .exe file on all machines and compare.
Also, post your batch file code so we can exactly see how you start the .exe.
You could consider not using start at all. Simply start the executable directly.
Did you try using call in the batch file. it runs the exe in the same window. as the batch file. The next statement in the batch file is executed after this exe is finished running
In order to do this you have to run an executable from the directory where it is located, and also have to avoid the use of "start" command.
For example:
cd C:\MyDirectory\
MyApplication.exe -Parameter1 -ParameterN
I achieved showing output of my executable (no aforementioned solutions worked for me) in the same CMD window only via rights escalation script (it will launch your .bat/.cmd file as admin):
if _%1_==_payload_ goto :payload
:getadmin
echo %~nx0: elevating self
set vbs=%temp%\getadmin.vbs
echo Set UAC = CreateObject^("Shell.Application"^) >> "%vbs%"
echo UAC.ShellExecute "%~s0", "payload %~sdp0 %*", "", "runas", 1 >> "%vbs%"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
goto :eof
:payload
<<<start writing your commands from here. E.g.:
"C:\my program\launcher.exe" argument1>>>
pause
P.S. Don't forget to remove <<< and >>> from script.

Resources