1

I think starting a process minimized should be simple but I had no luck with outlook. How can I start Outlook minimized?

My attempt was this:

[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

static void Main(string[] args)
{
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = "OUTLOOK.EXE";

    IntPtr hWnd = Process.Start(startInfo).Handle;

    bool state = false;
    if (!hWnd.Equals(IntPtr.Zero))
        state = ShowWindowAsync(hWnd, 2);

    // window values: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx

    Console.WriteLine(state.ToString());
    Console.Read();
}

4 Answers 4

2

Have you tried using ProcessStartInfo.WindowStyle, setting it to ProcessWindowStyle.Minimized?

2
  • @jwillmer: Rather than just say "no luck" can you describe what happened when you tried?
    – Jon Skeet
    Commented Aug 1, 2012 at 17:31
  • 1
    sorry of course I will: At my work pc I couldn't find any difference but right now at my home pc it seems like the loading screen is minimized if I set the value to ProcessWindowStyle.Minimized but the main program will be still expand.
    – jwillmer
    Commented Aug 1, 2012 at 18:23
0

I have found out that if you wait until Outlook have started and you send the command below the window will minimize to tray. Now the only thing to accomplish in order to minimize outlook is to loop till it is ready :-)

var hWnd = Process.Start(startInfo);
ShowWindowAsync(hWnd.MainWindowHandle, 2);
0

I have solved it but I like to hear your comments if you think the solution can be improved. I also have posted the solution on my blog with some more details at http://jwillmer.de/blog/2012/08/01/how-to-start-outlook-minimized-with-c/

[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

// console application entry point
static void Main()
{
    // check if process already runs, otherwise start it
    if(Process.GetProcessesByName("OUTLOOK").Count().Equals(0))
        Process.Start("OUTLOOK");

    // get running process
    var process = Process.GetProcessesByName("OUTLOOK").First();

    // as long as the process is active
    while (!process.HasExited)
    {
        // title equals string.Empty as long as outlook is minimized
        // title starts with "öffnen" (engl: opening) as long as the programm is loading
        string title = Process.GetProcessById(process.Id).MainWindowTitle;

        // "posteingang" is german for inbox
        if (title.ToLower().StartsWith("posteingang"))
        {
            // minimize outlook and end the loop
            ShowWindowAsync(Process.GetProcessById(process.Id).MainWindowHandle, 2);
            break;
        }

        //wait awhile
        Thread.Sleep(100);

        // place for another exit condition for example: loop running > 1min
    }
}
0

You can use this this.Application.ActiveExplorer ().WindowState = Outlook.OlWindowState.olMinimized;

It minimizing your corrent outlook window (this = ThisAddIn class)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.