Answered Visible and not visible Outlook

ksor

Active member
Joined
Jul 4, 2019
Messages
33
Programming Experience
10+
I've made a console program to run by the scheduler every sunday to copy my Outlook mail file.

If Outlook runs, the program stops it, do the copying and starts Outlook again and send a mail with the result of the copying.

It works nicely but lately I've had a problem on ONE single machine - when Outlook starts up again it's IN-visible - the user then ofcause starts Outlook manually and then 2 instances are running.

Not that it matters that 2 instances runs ... but why is it invisible ?

I use this essential snippet of code to start Outlook again:

Starting Outlook:
                    else if (args[0].ToUpper()=="START") {
                        ProcessStartInfo startInfo = new ProcessStartInfo("Outlook.exe");
                        startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                        Process.Start(startInfo);
                    }
                    else if (args[0].ToUpper()=="GO") {
                        if (ThisIsRunning("Outlook")) {
                            StopExecutionOf("Outlook");
                        }
                        // Her testes på OM ALLE parametre ER angivet !
                        if ((Properties.Settings.Default.Datafil.ToString()=="") |
                            (Properties.Settings.Default.SikkMappe.ToString()=="") |
                            (Properties.Settings.Default.Modtager.ToString()=="") |
                            (Properties.Settings.Default.Bruger.ToString()=="") |
                            (Properties.Settings.Default.Password.ToString()=="")){
                            handleParams();
                        } 
                        else{
                            File.Copy(Properties.Settings.Default.Datafil.ToString(), Properties.Settings.Default.SikkMappe.ToString(), true);
                            sendMail(Properties.Settings.Default.Modtager.ToString(), txtSuccess);
                            ProcessStartInfo startInfo = new ProcessStartInfo("Outlook.exe");
                            startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                            Process.Start(startInfo);
                        } 
                    }
                    else {
                        args=null;
                        ShowWindow(handle, SW_SHOW);
                        someThingWrong();
                    }
 
How exactly are you stopping Outlook in your StopExecutionOf()? Are you letting Outlook shutdown gracefully by sending it the close and quit messages and waiting for the process to end, or are you forcing the process to stop running (and potentially corrupting the .PST files)?

Are you sure that Outlook terminated fully?

Are you sure that there is not some other process running that is trying to also work with Outlook Object Model and is restarting Outlook while you are still copying the .PST files or start Outlook back up?
 
Here is how I'm stopping Outlook:

C#:
       private static Boolean StopExecutionOf(String r) {
            foreach (Process clsProcess in Process.GetProcesses()) {
                if (clsProcess.ProcessName.ToLower()==r.ToLower()) {
                    try {
                        clsProcess.Kill();
                    }
                    catch {
                        return false;
                    }
                    return true;
                }
            }
            return false;
        }

I can see in the systemtray that it stops and too in (I cant remember what it's called = the CTRL+ALT+DELETE list of processes - no instance is shown there - and why does the problem come up - it has been working for years with NO corruption of the PST-file.
REMEMBER it ALL works - except Outlook is INVISIBLE - it starts invisible and send the mail as supposed to - the user just manually have to start Outlook (again !) to SEE the mail - it's a little annoying !
 
A task will only run interactively if configured with 'Run only when user is logged on'.
 
Solution
Welcome to the strange ways of Outlook... And I say that with all feeling since I used to work on the older version of Outlook many many years ago. Even back then, there was a lot of voodoo with regards as to it, and that was working as an insider.

Anyway, when you restart outlook.exe, try using the "/restore" command line parameter. It's supposed to try to restore the current views that you had when Outlook terminated abnormally (like when you just ungraciously killed the process in your code above).
 
>JohnH writes "A task will only run interactively if configured with 'Run only when user is logged on'."

Maybe there is a clue here - I can't remember right now how I did set up the Scheduler at that point - I'll have to check that !

> Skydiver
Do you have a snippet of code showing how to "GRACIOUSLY kill" Outlook ;-) ?
 
>JohnH writes "A task will only run interactively if configured with 'Run only when user is logged on'."

That was the cause - when I set the new tast up in Scheduler I chouse "IF the user was logged on OR not" - and I should be "The user shall be logged on" for Outlook to show up !

THX for your time !

Still I would be happe for a snippet of code showing how to "GRACIOUSLY kill" Outlook ;-) ?
 
Back
Top Bottom