Wait until application finished

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
batchelor
Posts: 11
Joined: 12 Sep 2010 08:54

Wait until application finished

#1 Post by batchelor » 23 Feb 2012 15:09

I wish to run a program that doesn't unload its exe from the services (in Task Manager), for which purpose I added a taskkill command:

@echo off
start "%~1" C:\Folder\xyz.exe "%~1"
TASKKILL /F /IM "xyz.exe"
exit

Logically, it doesn't work because it immediately turns itself off this way.
What can I write before "TASKKILL" so that the batch file waits with that command until I turn xyz.exe off?
I want it to stop before "TASKKILL" and continue only after I terminate xyz.exe.

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Wait until application finished

#2 Post by alan_b » 23 Feb 2012 15:11

Try
start /WAIT "%~1" C:\Folder\xyz.exe "%~1"

If you need more help try the comand

START /?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Wait until application finished

#3 Post by Squashman » 23 Feb 2012 16:00

You may be caught in a catch22. Some programs do not play nice with the /wait switch either. But either way how would we know the program is finished if it is not closing itself?

batchelor
Posts: 11
Joined: 12 Sep 2010 08:54

Re: Wait until application finished

#4 Post by batchelor » 23 Feb 2012 16:35

Yes, it is the catch - it just continues waiting even though I terminate xyz.exe.
There may probably not be that simple a solution...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Wait until application finished

#5 Post by foxidrive » 23 Feb 2012 22:46

You can probably use the same batch file to start the process, and use it again to kill the process.

(Untested):

Code: Select all

@echo off
If not exist "%temp%\flag.txt" (
type nul >"%temp%\flag.txt"
start "%~1" "C:\Folder\xyz.exe" "%~1"
) else (
TASKKILL /F /IM "xyz.exe"
del "%temp%\flag.txt" 2>nul
)

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Wait until application finished

#6 Post by Liviu » 24 Feb 2012 01:39

batchelor wrote:Yes, it is the catch - it just continues waiting even though I terminate xyz.exe.
How do you define "terminate" then?

Some apps have a "minimize to systray instead of closing" configuration setting, which might be what you are seeing (and, in that case, all that's needed is turn the config setting off, no taskkill required). But you gave no context or details on the actual scenario.

Liviu

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Wait until application finished

#7 Post by foxidrive » 24 Feb 2012 02:13

Liviu wrote:Some apps have a "minimize to systray instead of closing" configuration setting, which might be what you are seeing


Good thinking.

But you gave no context or details on the actual scenario.


That's the perennial question that we-who-like-to-give-support have to face: wtf is the OP *really* trying to do. ;)

batchelor
Posts: 11
Joined: 12 Sep 2010 08:54

Re: Wait until application finished

#8 Post by batchelor » 24 Feb 2012 14:58

Thanks guys.
Terminate: Click the x button on the upper right. In WinXP the exe disappears from the processes listed in Task Manager, in Win 7 it doesn't. So when I start it again, it next time doesn't request the password as it should, but just reactivates the exe in the process.

@foxidrive: thanks, it did work, except that it also never terminates the exe... but it still remains in the Task Manager.

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Wait until application finished

#9 Post by alan_b » 24 Feb 2012 16:04

According to Google, xyz.exe is either a virus or a Trojan.
Why are you running a known malware ? :P

More seriously, different executables have different characteristics when closing.

If you have a SPECIFIC program for which you need SPECIFIC advice, we need to know what that SPECIFIC program is.

Incidentally, I think your terminology is inappropriate/misleading in your first sentence :-
I wish to run a program that doesn't unload its exe from the services (in Task Manager),

I assume that what you really meant was :-
I wish to run a program that doesn't unload its exe from the processes (in Task Manager)


Task Manager will show under the processes TAB various running executables.
A large number are launched by "Automatic Services" before the user ever gets to log on,
Another large number are those present when you, the User, has "Run a Program".
A much smaller number are "Manual Services" which are possibly triggered by system events, or by your running a program that chooses to use a system "Service".

Clicking the top right corner of a Application Window will normally close the Application.
If a System "Automatic Service" or "Manual Service" is responsible for that Window we have a different ball game and different rules.
My only experience in this region was H.P. Printer software that was determined to use the Internet for some "Print to Web" feature.
I finished up by location the EXE responsible for the process and changing the extension to TXT.

Alan

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Wait until application finished

#10 Post by foxidrive » 24 Feb 2012 16:50

batchelor wrote:@foxidrive: thanks, it did work, except that it also never terminates the exe... but it still remains in the Task Manager.


Put a pause statment after the DEL command and read the console window which should tell you why it didn't terminate.

batchelor
Posts: 11
Joined: 12 Sep 2010 08:54

Re: Wait until application finished

#11 Post by batchelor » 26 Feb 2012 09:43

@alan_b: Well, my friend, I just call it xyz.exe, but it has another name, of course… in this case Passcrypt.exe, a password safe. As I wrote above, I DO want it to terminate the exe from the processes, when I close the program. It does in XP, but not in Win7.

batchelor
Posts: 11
Joined: 12 Sep 2010 08:54

Re: Wait until application finished

#12 Post by batchelor » 26 Feb 2012 09:56

Passcrypt.exe doesn't show up in the list of processes, even if it still appears in the Task Manager.
Adding PAUSE doesn't show why it doesn't terminate the exe process, but I have the option to click the batch window once more to additionally terminate the process once program is closed. So I have to click twice...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Wait until application finished

#13 Post by foxidrive » 26 Feb 2012 10:13

batchelor wrote:Passcrypt.exe doesn't show up in the list of processes, even if it still appears in the Task Manager.


It could be listed as another exe, perhaps.

Adding PAUSE doesn't show why it doesn't terminate the exe process, but I have the option to click the batch window once more to additionally terminate the process once program is closed. So I have to click twice...


I don't understand - you click once to launch it. And you click once to kill the process.
That's what I said it was meant to do.

What *is* displayed on the screen when pause is after the del command?

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Wait until application finished

#14 Post by alan_b » 26 Feb 2012 15:20

Are you sure Passcrypt.exe is good and safe ?

The nice thing about knowing a specific name is that Google may tell us useful information to resolve problems.
In this particular case I gained no such problem resolution,
but an awful lot of results, many suggesting it was harmless and others suggesting a Trojan.

I am not saying it is bad - just asking if you are confident

Alan

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Wait until application finished

#15 Post by Liviu » 27 Feb 2012 00:18

batchelor wrote:@alan_b: Well, my friend, I just call it xyz.exe, but it has another name, of course… in this case Passcrypt.exe, a password safe. As I wrote above, I DO want it to terminate the exe from the processes, when I close the program. It does in XP, but not in Win7.

Don't have any first hand experience with passcrypt, but I notice that it has a "system tray" tab among its advertised Options settings http://www.seamistsoftware.com/screenpopup.aspx?image=options_preferences.gif. What's under that tab, and are the settings the same between your xp/win7 machines?

Just saying, but taskkill'ing a program in charge of maintaining some database file with critical info may easily backfire someday.

Liviu

Post Reply