Monitoring Process Exits in a Custom Action

孤街醉人 提交于 2020-01-06 10:54:31

问题


All –

I need to carry out several tasks silently via Custom Actions. Essentially, I need to install and license a 3rd party application after I've laid down my own bits:

  1. I install my bits into the Application Folder
  2. I launch a custom action to Install the 3rd party app via FooSetup.exe
  3. I launch another custom action to license the third party app via FooLicense.exe, installed during step 2.

During the Commit phase of the installer, I fire this code to launch the silent setup of the 3rd party application:

[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Commit(IDictionary savedState)
{
  base.Commit(savedState);

  ProcessStartInfo startInfo = new ProcessStartInfo();
  startInfo.Arguments = "/verysilent";
  startInfo.FileName = Context.Parameters["TARGETDIR"].ToString() + "fooSetup.exe";
  Process myProcess = System.Diagnostics.Process.Start(startInfo);
}

It works fine – however, I can’t begin “phase 3” (license the third party app) until fooSetup.exe actually completes.

What is the best practice to approach this scenario? I’m guessing I’m going to have to setup an Event Handler on myProcess to watch for the exit of fooSetup.exe? (I've validated that FooSetup.exe indeed exits post-completion while in silent mode)

Any examples out there? I’m a Business Intelligence guy vs. a C# jockey, so any samples/pointers you push me towards would be appreciated.


回答1:


I guess Process.WaitForExit() is what you want. http://msdn.microsoft.com/en-us/library/fb4aw7b8.aspx



来源:https://stackoverflow.com/questions/12899138/monitoring-process-exits-in-a-custom-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!