I am trying to write a batch file which when invoked through cmd would launch 3 programs consecutively. Here is what I have so far:
cd C:\Program Files\CPUID\CPU-Z\
cpuz.exe
cd "C:\Program Files\Core Temp\"
"Core Temp.exe"
cd "C:\Program Files (x86)\EVGA Precision X\"
EVGAPrecision.exe
The problem is that when I execute this batch file it launches the first program and then simply pauses. Only when I close the first program does it go on to the second command. Keep in mind that each of these programs require permission from the user to run through the "Do you want to allow the following program to make changes to your computer?" thing.
The ideal scenario is to have all program launch at the same time with out prompting for permission, but if that is impossible, I'm fine with clicking "Yes" for each one of them as long as they still launch consecutively and I don't have to close each program.
This should do what your looking for:
start "" "C:\Program Files\CPUID\CPU-Z\cpuz.exe"
start "" "C:\Program Files\Core Temp\Core Temp.exe"
start "" "C:\Program Files (x86)\EVGA Precision X\EVGAPrecision.exe"
Related
I have a program that uses batch scripts internally since I do not have the newer software to that will allow me to create an exe to run inside the program. This is for my job, so I cannot purchase software and make it happen myself. So my work around with what I have is to create a batch file for a script that will run it automatically from within the program when clicking its icon. Problem is (50/50) when I run the .bat the command prompt opens and runs just fine then closes the command prompt after executing. Good. But then It also closes my program and I do not know how to prevent it from doing so. Is there something I need to add to the command prompt that will not close the program i am using the script in?
"C:\Program Files (x86)\JDA\Intactix\Space Automation\autopilot.exe" /play "C:\Users\Public\Documents\AAA SWB Custom\SCRIPTS\SWB - Desc 39 Survey Date.aps"
The autopilot.exe opens up Space Automation where scripts are written and played. The command prompt opens this program and runs the script then closes the program and the command prompt. But for some reason it also closes the program I am running it in.
ignore what i am saying and just copy the code lol kasdijkiojoipgo mipogaio goi juioj oiefj ioqj iojioqejoqeg oeiqwjc oij qoijfq oije oije fgiououimgqiou moi gq mqeo meqoio imo igoiqe eogeoqi jioqejgo joi moeigeqoi mgoi mohij rowt pokjpoq jpoerig iopw4i gmjwreo miomgwpj gioj
cd "C:\Program Files (x86)\JDA\Intactix\Space Automation\"
autopilot.exe /play "C:\Users\Public\Documents\AAA SWB Custom\SCRIPTS\SWB - Desc 39 Survey Date.aps"
or just
cd "C:\Program Files (x86)\JDA\Intactix\Space Automation\"
start autopilot.exe /play "C:\Users\Public\Documents\AAA SWB Custom\SCRIPTS\SWB - Desc 39 Survey Date.aps"
I hope i helped you.
I'm trying to open two VSCode projects from a batch file, and then close the batch file and let the VSCode run.
Tried several methods:
This does not close the batch file, and if I close it by my self, VSCode terminates:
start "" "C:\Program Files\Microsoft VS Code\Code.exe" c:\project1
start "" "C:\Program Files\Microsoft VS Code\Code.exe" c:\project2
exit
This one opens two cmds, each one opens VSCode and then terminates, but often it also holds and does not close for some reason:
start cmd /c "code c:\project1 && exit"
start cmd /c "code c:\project2 && exit"
Simply running VSCode sometimes holds the execution of the next commands altogether:
code c:\project1
code c:\project2
.
. <-- Next commands don't run
.
So how should I open VSCode in a way that will not stop the execution and will not depend on the terminal remaining open?
I know this topic is more than 2 years old now, but I was facing this problem right now and just found out the solution.
Try calling code.exe directly instead the code.cmd that is in system path.
"%localappdata\Programs\Microsoft VS Code\Code.exe" C:\project1
"%localappdata\Programs\Microsoft VS Code\Code.exe" C:\project2
exit
I know how to do this in C++, C#, etc, but I've got a simple BAT file that does a couple operations on a file, opens it in Notepad++, and proceeds to the next file. Because I want to wait for it to finish running on 2 to 20 files, I want it to run in the background until it's finished.
Here's my line to open the file in Notepad++:
start "" /b "C:\Program Files (x86)\Notepad++\notepad++.exe" "%filepath%"
Is it possible to START a program so that it runs without stealing focus?
This is not a general solution, but for your specific requirement (notepad++) you could try command line option of notepad++.exe -systemtray
from notepad cmd line spec:
-systemtray
Start Notepad++ minimised in the system tray, aka notification area
(There is an option to start program minified start /min, but n++ does not honor it... it works with regular notepad, though)
I am writing a batch file on my Windows 8.1 machine. In one section of my batch file I need to start a command prompt in the "current working directory".
So far, this is what my batch file looks like:
#echo OFF
set WORKING=%cwd%
start cmd.exe /K pushd %WORKING%
exit
Let's say the batch file is located in the folder C:\Temp\Utilities. If I open an explorer window and double click the batch file to run it everything works great. A new command prompt is created in the directory C:\Temp\Utilities. However, if I right-click the batch file and select Run as administrator the working directory is no longer the location of the batch file, it's C:\Windows\System32.
Similarly, if I create a shortcut to the batch file in a different folder (for example. C:\Temp) and repeat the two steps above the results are the same. If I double click the shortcut and run it as a normal user the working directory is what I would expect. (Note, the working directory for the shortcut it's whatever is set for "Start in" of the shortcut properties, not the location of the batch file.) If I right click the shortcut and run it as administrator I again get a command prompt opened to the folder C:\Windows\System32.
I assume this is a "bug" or "feature" (if you want to call it that) in Windows 8.1 and it probably happens because execution environments for programs run as administrator are forced to run in the System32 folder? (I remember with Windows 7 this did not happen so it must be a new feature to Windows 8.)
I found one way to fix the issue and stop the command prompt from starting in C:\Windows\System32. I did this by modifying the following line in the batch file:
set WORKING=%~dp0
Doing it this way sets the working directory to the location of the batch file. With this change, no matter how I run the batch file or the shortcut (administrator or normal) the working directory ends up being the same, C:\Temp\Utilities.
The problem with this solution is I don't want the working directory to always be the location of the batch file. If the batch file is run directly then it's okay but if I run it from a shortcut I need the working directory to be whatever is set in the "Start in" property of that shortcut. For example, if the batch file is located in the folder D:\Temp\Utilities this is what I need to happen regardless of whether I run as administrator or not:
Shortcut Location Start In Property Command Prompt Working Directory
-------------------- ------------------- ------------------------------------------
C:\Temp <undefined> D:\Temp\Utilities
C:\Data\bin C:\Data\bin C:\Data\bin
C:\Data\bin D:\Temp\Utilities D:\Temp\Utilities
What this means is I can't always use %~dp0 to set the working directory in my batch file. What I need is some way for the batch file to know if it was run either directly or by a shortcut. If the batch file is run directly then the working directory is easy to get, it's just the value of %cwd%. If the batch file is run by using a shortcut, I don't know how to get the "Start in" property inside the batch file.
Does anyone know how I can do these two things inside my batch file:
1. Check whether it was run directly or by a shortcut.
2. If run by a shortcut, get the "Start in" property of the shortcut that started it.
Thank you,
Orangu
UPDATE
I found sort-of a "hackish" way to fix the issue. For the shortcut I edited the "Target" field and changed it to the following:
cmd.exe /k pushd "C:\Temp" && "D:\Temp\Utilities\batchfile.bat"
Now the working directory can be obtained by calling %CD% in the batch file and this works for both administrator and normal users. It does not, however, work for the case when I run the batch file directly. I still need to use %~dp0 in that case.
I don't like this solution, however, because it requires me to manually change all shortcuts I make and it also makes the icon look like a cmd prompt icon rather than a batch file.
Have you already considered to not use shortcuts at all?
You could e.g. create a batchfile_exec.bat containing your call
REM optionally do
REM cd /D working_directory
REM if you want to force a special working directory
D:\Temp\Utilities\batchfile.bat
and replace all the shortcuts with batchfile_exec.bat. If you double-click batchfile_exec.bat, the working directory will be the one containing batchfile_exec.bat.
I personally don't like Windows shortcuts that much, because they are hard to handle within a revision control system. As you also noticed, it is very time consuming if you want to modify a lot of them.
By the way: If batchfile.bat was designed/written to be always run from the direcory where it is located, you might also consider to modify batchfile.bat to force that behaviour:
setlocal
cd /D %0\..
REM your original content
endlocal
In %0 the path to the batchfile is stored.
The trick is to assume that %0 is a directory and then to change one level lower based on that directory. With /D also the drive letter is changed correctly.
The cd command doesn't care if %0 is really a directory. In fact %d doesn't even have to exist (%0\dummy\..\.. would also work).
The setlocal command is to have the working directory being restored when batchfile.bat has finished (this would be good if batchfile.bat was called form another batch file).
I noticed that the endlocal command is not really necessary in this context since it is applied implicitly when batchfile.bat finishes.
I have three different commands that I want to execute my running one script,
I created a file called as myscript.bat
I want the following two commands to run in sequence when I run the script:
cd C:\Users\johnDoe\Idea\View\Proxy
node proxy.js
PS:And after that I want the cmd to be left open, not close automatically
Leave the bat file as it is, but run it with cmd /k myscript.bat. Also, if there's a chance of the command window opening by default on another drive, you might want to add the line C: to the beginning of the script to change volumes. cd changes folders within a given volume, but it doesn't actually change volumes.
Alternatively, if you just want the window to stay open so you can read the output, but you don't actually want to run any additional commands in it after your commands finish, you can just add the line pause at the end of the script.
#reirab's answer contains the crucial pointer: use cmd /k to create a console window that stays open.
If you don't want to use cmd /k explicitly - say, because you want to open the batch file from Explorer, you have 2 options:
[Suboptimal] Add a cmd /k statement as the last statement to your batch file.
[Better] Write a wrapper batch file that invokes the target batch file with cmd /k.
For instance, if your batch file is startProxy.bat, create another batch file in the same folder, name it startProxyWrapper.bat, and assign the following content:
#cmd /k "%~dp0startProxy.bat"
When you then open startProxyWrapper.bat from Explorer, a persistent console window (one that stays open) will open and execute startProxy.bat.