Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can check with C# if Microsoft Outlook is already open?

Tags:

c#

email

outlook

I have tried looking for the answer to this question... Forgive me if I have overlooked it.

What I am trying to do is automate sending an email. I have everything I want in this code but the code assumes that Outlook is NOT open.

Is there a way for me to test if Outlook is open before it opens another instance of Outlook?

                Microsoft.Win32.RegistryKey key =
           Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\microsoft\\windows\\currentversion\\app paths\\OUTLOOK.EXE");
            string path = (string)key.GetValue("Path");
            if (path != null)
                System.Diagnostics.Process.Start("OUTLOOK.EXE");
            else
                MessageBox.Show("There is no Outlook in this computer!", "SystemError", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
like image 651
Piggie_Pie Avatar asked Sep 17 '25 01:09

Piggie_Pie


1 Answers

Since I like clean one-liners, here's what I used:

if (System.Diagnostics.Process.GetProcessesByName("OUTLOOK").Any())
  return true;
like image 91
Mausam Avatar answered Sep 19 '25 16:09

Mausam