2

I would like to launch an application automatically, always when some other application finishes. Is it even possible to perform?

My specific situation is: User connects to remote desktop and then, some Iexplorer window with specific page must occurre.

So far, I found solution using start /wait:

start /wait prog1.exe
start /wait prog2.exe

but this solution is not good enough since the first program must be always opened via the cmd script.

I tried to perform this task using task scheduler but unfortunately I could not find proper interruption or activity that would meet my needs.

Thank you for any help.

2 Answers 2

0

You have made 90 percent of the way to a solution. If the connection method is via RDP, one can start off a program when a user logs in. Put the "start" commands in a .BAT/.CMD file and via "Advanced" tab of the RDP invoke it as part of user log in.

3
  • Thank you for your reaction, unfortunately maybe I did not formulate my demands clearly: I need program to run on the local computer NO on the remote one (NO on the computer the user tries to connect to). The time sequence should be: 1) User connects to the remote computer 2) in the very moment, on the LOCAL machine program P is executed 3) user terminates remote connection 4) in the very moment, on the LOCAL machine program Q is executed Do you have any suggestion for this situation, please?
    – botajzorek
    Commented May 3, 2014 at 15:37
  • If the commands need running on local machine, one can try "CALL" command. "CALL prog1.exe" will wait until prog1 finishes and only then continue to next command (prog2.exe).
    – Irony
    Commented May 6, 2014 at 8:11
  • Actually, your comment helped me in the solving the situation. I combined Visual Basic simple script and CALL command to achieve the solution. Thank you very much.
    – botajzorek
    Commented May 8, 2014 at 10:36
0

If PowerShell is an option, you could use Task Scheduler to start this script in a hidden PowerShell window.

This will watch for the mstsc.exe process to start, then open notepad.exe when each mstsc.exe process exits.

# The action to be performed for every new process event.
$action = {
    $target = $EventArgs.NewEvent.TargetInstance
    if($target.Name -eq 'mstsc.exe') {
        # Run action as a job in order to handle multiple new calc.exe
        # processes. Otherwise, the script will be blocked waiting for
        # the first calc.exe to exit.
        $jobScript = {
                param($ProcessId) 
                (Get-Process -Id $ProcessID).WaitForExit()
                notepad.exe
            }
        Start-Job -ScriptBlock $jobScript -ArgumentList $target.ProcessId
    }
}

$query = @"
Select * From __InstanceCreationEvent within 3
Where TargetInstance ISA 'Win32_Process'
"@

Register-WMIEvent -query $query -Action $action -sourceIdentifier "New Process" 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .