locked
Calling script once a process is terminated RRS feed

  • Question

  • Hello,

    I am having fun experimenting with app-v 5 scripting. Here is the scenario. Sorry if i am unable to present it well.

    I have a package "A" which installs add-in to excel. I connected A ad MS Office using connection group. Now, I have to delete a file in appdata folder once excel is closed and it has to be scheduled on every launch of app A. Note :I am calling excel here using app A. So, here is the process flow as in case of add-ins:

    Launch A -> A triggers Excel -> A terminates and Excel stays in the process list ->Close Excel File ->The file which has to be deleted gets created in appdata.

    Now, my question is how to use app-v scripting to  delete that file. I tried <StartProcess> event and as expected it deletes the file at the launch but i have to delete it after excel loses.

    Tried ExitProcess but again the process A in my package exits as soon as excel launches and hence won't work.

    Is there any way to call my script as soon as the excel terminates or any other workaround?

    Thanks

    Wednesday, July 15, 2015 8:16 PM

Answers

  • How about TerminateVirtualEnvironment?

    This will only work if the application closes properly.


    PLEASE MARK ANY ANSWERS TO HELP OTHERS Blog: rorymon.com Twitter: @Rorymon


    Wednesday, July 15, 2015 9:55 PM

All replies

  • How about TerminateVirtualEnvironment?

    This will only work if the application closes properly.


    PLEASE MARK ANY ANSWERS TO HELP OTHERS Blog: rorymon.com Twitter: @Rorymon


    Wednesday, July 15, 2015 9:55 PM
  • Check this link

    http://www.tmurgent.com/TmBlog/?p=1154.


    (Please click on "Vote as Helpful" and/or "Mark as Answer", if it has helped you. )

    Thursday, July 16, 2015 5:49 AM
  • Thank You Rorymon! Going with your suggestion as did not find any better solution. I was exploring other options since use of TerminateVirtualEnvironment requires all the virtual processes to be closed properly for the file to be deleted, which might not be a real time scenario.

    Appreciate your help!

    Tuesday, July 21, 2015 11:21 PM
  • Does the file really need to be removed after you shutdown excel? Why not remove the file as soon as you start app A the next time? This could easily be done with startve.
    Thursday, July 23, 2015 10:40 PM
  • Yes actually it needs to be deleted once the  excel is closed for a weird reason though. The presence of this file causes unexpected delay in the opening of my app in the connection group. So, if u dont delete it at shutdown the next time you try n open ur app it takes more than a minute to open up. Have observed the same behaviour with many other excel plug-in apps recently. And deleting this file helps to prevent that unexpected buffer time.

    Have not observed any cons/adverse effect of deleting this file but still evaluating. Hope it answers your question.

    Friday, July 24, 2015 1:36 PM
  • The presence of this file causes unexpected delay in the opening of my app in the connection group.

    Ok great, so you can delete the file the next time the virtual environment of the package opens, instead of deleting it after it shuts down.
    Monday, July 27, 2015 10:19 AM
  • You can do this with PowerShell.  

    http://trentent.blogspot.ca/2014/07/call-powershell-from-cmdexe-and.html

    Start-Sleep -s 60 $localSession = Get-ChildItem 'HKCU:\Volatile Environment' -name $process = get-process ^| where {$_.sessionID -eq $localSession} ^| where {$_.processName -eq "MetaVision.exe"} if ($process -eq $null) {logoff.exe} $process.waitforexit()
    //Do something after process exit

    powershell.exe -ExecutionPolicy Unrestricted -WindowStyle Hidden -File "%TEMP%\proc_logoff.ps1"


    You may need to get localSession from the Citrix key or tasklist.exe or something like that.  If I recall, this script, while doing what you describe you want, wasn't 100% accurate with the local session variable.


    • Edited by TrententMVP Tuesday, July 28, 2015 7:25 PM updated additional command after 'waitforexit'
    Tuesday, July 28, 2015 7:25 PM