CreateProcess and waitforsingleobject, with outlook.

S

stefan.sedich

Hi I am trying to open an email in outlook with the following

string command = "c:\\Program Files\\Microsoft
Office\\OFFICE11\\OUTLOOK.EXE c:\\a.msg";
StartupInfo si = new StartupInfo();
ProcessInformation pi = new ProcessInformation();
si.cb = 68; //sizeof(si);
try {
int i = CreateProcess(null, command, 0, 0, false, 0, 0,
null, si, pi);
Int32 INFINITE;
unchecked { INFINITE = (int)0xFFFFFFFF; }
IntPtr f = new IntPtr(pi.hProcess);

WaitForSingleObject(f, INFINITE);

DocumentEventHandler h = DocumentClosedEvent;
if (h != null) h(mDocumentID);
} catch (Exception e) {
Console.WriteLine(e);
}

basically i want to open the email file, wait for the user to close it
then fire an event so i know the document was closed, this works fine
for word docs, powerpoint, sometimes works for pdf, but for outlook it
doesnt, unless outlook is fully closed and i do it. I have also tried
using the System.Diagnostics.Process, with the wait, and it has the
same effect.

Has anyone got a solution to my problem i am going crazy with this and
need it solved asap. I have also tried looking at the processes on the
system and their threads and checking if any match the id processinfo
has, but to no avail.

Please if someone can help me out here it would be appreciated.

Thanks
 
B

Barry Kelly

Int32 INFINITE;
unchecked { INFINITE = (int)0xFFFFFFFF; }

You know about Timeout.Infinite, right? And that "-1" is just as good?
basically i want to open the email file, wait for the user to close it
then fire an event so i know the document was closed, this works fine
for word docs, powerpoint, sometimes works for pdf, but for outlook it
doesnt, unless outlook is fully closed and i do it.

That's probably because the new process quits as soon as it's informed
the existing Outlook instance of the request.
Has anyone got a solution to my problem

I think you need to look into Office Interop and manipulating Outlook
with COM, but I haven't done what you're trying to do. Just a
suggestion.

-- Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top