Find default email client

可紊 提交于 2019-12-01 17:09:26

Use the Registry class to search the registry. This console app demonstrates the principle.

using System;
using Microsoft.Win32;

namespace RegistryTestApp
{
   class Program
   {
      static void Main(string[] args)
      {
         object mailClient = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail", "", "none"); 
         Console.WriteLine(mailClient.ToString());
      }
   }
}

You can look in the registry on the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail
Jonathan

You can read this registry key from

HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail

Default email client depends on the user. HKLM lists all registered email clients; the first one returned may not be the current user's default. Better to read HKEY_CURRENT_USER\Software\Clients\Mail.

Also this only gives you the name of the email application. If you want its executable file name, you have to go on with something like:

object mailCommand = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail\" + mailClient.ToString() + @"\shell\open\command", "", "none");

and then remove anything extraneous from the command-line string that you don't need (quotes, parameters).

I think you should be able to find that info in the registry at HKLM\Software\Clients\Mail.

Look for the default string value.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!