B
Brian Kavanaugh
If there's a better newsgroup to post this in, please let me know. I'm
trying to start MS Word and get notification when it exits. The basic case
works fine, but if Word or Outlook is already running - or is started while
my instance of Word is still open, I get problems. Here's my basic code:
ProcessStartInfo psi = new ProcessStartInfo( );
psi.FileName = "<path to executable>\winword.exe";
psi.UseShellExecute = false;
psi.Arguments = String.Format( "\"{0}\"", fileName );
Process process = new Process( );
process.EnableRaisingEvents = true;
process.Exited += new EventHandler(process_Exited);
process.SynchronizingObject = myForm;
process.StartInfo = psi;
process.Start( );
with psi.UseShellExecute = false:
1) If Outlook/Word is already running, Process.Exited fires immediately. It
appears it changes to the existing WINWORD process.
2) If this runs and Outlook/Word is started after I've run this (the
launched instance of Word is still open), it appears it hijacks my instance
of Word and I don't get notification until Outlook/Word is closed
with psi.UseShellExecute = true:
1) If Outlook/Word is already running, Process.Exited never fires
2) If this runs and Outlook/Word is started after running this, same as #2
above
How can I work around this? I'm working on an application that pulls
documents from a SQL Server database and displays them. If changes are made
to the document, I want to be able to update it after it has been closed or,
if they close my form that launched Word, warn them that any changes made
won't be saved (similar to the way Outlook works when you open a document in
a message). Can I force my instance of Word to launch in a separate process?
--Brian
trying to start MS Word and get notification when it exits. The basic case
works fine, but if Word or Outlook is already running - or is started while
my instance of Word is still open, I get problems. Here's my basic code:
ProcessStartInfo psi = new ProcessStartInfo( );
psi.FileName = "<path to executable>\winword.exe";
psi.UseShellExecute = false;
psi.Arguments = String.Format( "\"{0}\"", fileName );
Process process = new Process( );
process.EnableRaisingEvents = true;
process.Exited += new EventHandler(process_Exited);
process.SynchronizingObject = myForm;
process.StartInfo = psi;
process.Start( );
with psi.UseShellExecute = false:
1) If Outlook/Word is already running, Process.Exited fires immediately. It
appears it changes to the existing WINWORD process.
2) If this runs and Outlook/Word is started after I've run this (the
launched instance of Word is still open), it appears it hijacks my instance
of Word and I don't get notification until Outlook/Word is closed
with psi.UseShellExecute = true:
1) If Outlook/Word is already running, Process.Exited never fires
2) If this runs and Outlook/Word is started after running this, same as #2
above
How can I work around this? I'm working on an application that pulls
documents from a SQL Server database and displays them. If changes are made
to the document, I want to be able to update it after it has been closed or,
if they close my form that launched Word, warn them that any changes made
won't be saved (similar to the way Outlook works when you open a document in
a message). Can I force my instance of Word to launch in a separate process?
--Brian