470,602 Members | 1,633 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,602 developers. It's quick & easy.

How to detect when the external program closes the file?

I have problems with the following scenario:
My application is developed using C# under .NET. It must run on all Windows
versions starting from Windows 98.
The user must open different documents (txt, MS Office files, pdf,
pictures,…) from inside my app. It must start the file with the adequate
external program (Notepad, MS Office programs, Acrobat Reader, some Picture
viewer,... ) and be notified when this programs closes the document.
I have tried using various algorithms described on the newsgroups, like
using WaitForSingleObject and "Shell and Wait", but the problem is that it
does not work when the program being called is already started.
For example, when Outlook is started, the winword.exe process is running by
default. Opening a MS Word document from inside my app does not start a new
winword.exe process. Instead it just opens my document in a new Word window.
Because of that, starting winword.exe from my app, does not actually start
it, and I can't therefore wait for the process to end or check exit code or
do something similar.
I also tried enumerating the running processes, using
System.Management..ManagementClass methods, but I can’t get the information
about the files that a program has opened, just about it’s related DLLs and
EXEs (process.GetRelated("CIM_DataFile")).

I would like either to be notified when the file is closed or check, by
using some kind of a file handle, if my file is still opened.
Does anybody have a suggestion how to do it?

Thanx, ANA.

Nov 22 '05 #1
0 743

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.