I currently have a Windows batch file that runs an .exe file that uses a text file. I am trying to have the Windows batch file run the .exe file multiple times. This, however, requires the use of the same text files to read from. The command prompt gives me the error that the ".txt could not be opened" (I assume from this that it is already open.)
I am trying to see if there is a way in a .bat file to system call to kill that specific text file. The suggestions I see online are to use 'taskkill notepad.exe', but that returns "invalid argument" because the program doesn't open Notepad to use the text file.
Any suggestions would be appreciated.
It sounds like your existing script fails because the first instance of the exe is still open when the second instance starts.
One thing worth trying (and this depends on the nature of the application you are invoking) is to start the executable using the START /WAIT /B ... command. This makes the command interpreter wait for the program to exit before it moves onto the next command, so as long as nothing else is locking the text files you should be OK to move onto the next command.
Related
My code in the .bat looks like this.
"C:\users\reshade injector.exe"
C:\pathtogame\game.exe "added argument"
"c:\users\reshade injector.exe" <- if I open the actual file, it opens a command window and waits for my other application to launch. Is this a console app?
C:\pathtogame\game.exe "added argument" <- this works and launches my game
Another issue is that when launching the first .exe, a command window stays open. How do I make the command window not appear?
Can anyone help me with these two problems?
*edit for clarity
by opening the actual file, I mean double-clicking on the original reshade injector.exe.
When opening reshade injector.exe, two cmd windows open. They close as soon as I launch the game.exe.
I can't seem to get the reshade injector.exe to launch through the .bat file.
Batch will run any application it finds. If the application does not terminate (eg. it's waiting for user-input) then it will progress to the next instruction.
Some applications work by launching another (the user-interface) and then terminating, leaving the second application resident.
There's no way to tell without observing which approach any random application may take.
So - your batch should execute a file named c:\users\reshade injector.exe.
You say that "fails". Is there an error message generated? You would likely need to run the batch from the "command prompt" to see that message. Note that the Space between reshade and injector must be in the actual filename. If injector.exe is a file in a subdirectory called reshade, then you need a backslash between reshade and injector.
Having resolved the actual name of the first executable, try
#echo off
setlocal
start "" "firstexecutablename"
start "" "secondexecutablename" "arguments"
The first two lines prevent "command echoing" which is used for debugging and establish a "local environment" which ensures the "environment" for the batch file remains unchanged when the batch terminates. In the current case, these two lines are probably unnecessary, but it's SOP for batch files.
The batch should then close its session and window once it has attempted to launch the two applications.
The "" following start becomes the window-title. It can be any quoted string you like, but should not be omitted as start uses the first quoted string it finds as a window-title and may not recognise it as part of the executable/arguments.
I have got a batch script that ends with the following:
TITLE ALL DONE. You can close this window
ECHO.
ECHO ALL DONE. You can close this window
ECHO.
Pause
EXIT
it works fine when i run just the bat file (see below)
All Done! You can close this window.
Press any key to continue . . .
But when i create a self extracting exe out of the same bat script it wouldn't show this window after the execution and would just exit without any proper message.
Since the script works fine by itself, i am a bit lost on what could be causing this? How could i make the self extracting exe to show that window and prompt the user to close it like above.
It depends on the content of the executable, if your including other files to your archive be sure the program you run after extraction is your batch file.
If your only including that file i suggest you use BatToExe Converter
much more efficient way to build it, also it supports commandline, including other files, product info, admin manifest etc
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 can find plenty of answers on the internet about how to open a specific file, e.g. http://answers.yahoo.com/question/index?qid=20080102230630AAfu5dF
However, I need to provide a way of opening a non-specific file in a program called by a batch file.
To explain, here is an example. The user has a folder with 100 files in with the .xyz extension. He wants to be able to double click on ANY file and open it in his "XYZ Viewer," but to run his XYZ Viewer he needs to run a batch file that alters his registry and then runs the actual XYZ Viewer .exe.
If you select the batch file to be the default program via the "Always use the selected program to open this kind of file" tickbox, it will open the program, but without using the standard Windows function of opening the file that instigating the running of the program.
Is there a way to run the program through the batch file and for it to both run the program and open whichever file it was that instigated the running of the program?
I suspect this is impossible, but any suggestions would be very gratefully received!
Cheers.
Edit:
The program does eventually support opening a file placed as an argument to it.
My code is
reg import c:\regent\31.2.03.reg
start C:\Program\Program.exe
Does the program eventually support opening a file placed as an argument to it? In the example you linked, mspaint opens the first parameter given to it.
If your batch file isn't currently doing this, you will have to edit it to contain the batch parameter(s).
See http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true for some fuller documentation on it.
Essentially you want to add %1 somewhere like:
reg import c:\regent\31.2.03.reg
start C:\Program\Program.exe %1
when i run a .BAT file, it displays a message but immediately closes the window
how i can i force it to keep the window open so that i can see the message reeturned?
One way is to conclude the batch file with the
PAUSE
command.
You can also wrap it another batch file that calls the original and then pauses:
FOO.BAT
PAUSE
This also works for read-only batch files and compiled executables.
An alternative is to execute this bat file from an already opened command prompt (shortcut: Windows Key + R, type cmd, press ENTER)