Introduction
Following a question in Stack Overflow, I wrote this article which is about finding the user's email address, or several email addresses if he/she has.
Background
I looked at the Registry to find out how to do so, by searching for my own email address at the entire Registry. This is rather a tricky method to find out (in all probability) the user's email address from the stored email used to log on to Microsoft services. There are many email clients and methods, among them web mail (Gmail, Yahoo, etc.) and desktop clients (Outlook) and yet, assuming the typical user will use the main email address to sign in to Windows (and most of the Windows users use their Windows account's credentials to even log in to their PC), this works!
Using the Code
Windows stores used email accounts used as "Live ID" in the "UserExtendedProperties
" key in:
HKEY_CURRENT_USER\Software\Microsoft\IdentityCRL
The assumption is that this email was selected by the user as the Windows user name to log in to the PC and/or to other Windows services.
Therefore, you can get the email accounts using the following code:
{
HKEY key;
TCHAR achKey[MAX_KEY_LENGTH]; DWORD cbName; TCHAR achClass[MAX_PATH] = TEXT(""); DWORD cchClassName = MAX_PATH; DWORD cSubKeys = 0; DWORD cbMaxSubKey; DWORD cchMaxClass; DWORD cValues; DWORD cchMaxValue; DWORD cbMaxValueData; DWORD cbSecurityDescriptor; FILETIME ftLastWriteTime;
DWORD i, retCode;
TCHAR achValue[MAX_VALUE_NAME];
DWORD cchValue = MAX_VALUE_NAME;
if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\IdentityCRL\\UserExtendedProperties",
NULL, KEY_READ, &key) == ERROR_SUCCESS)
{
retCode = RegQueryInfoKey(
key, achClass, &cchClassName, NULL, &cSubKeys, &cbMaxSubKey, &cchMaxClass, &cValues, &cchMaxValue, &cbMaxValueData, &cbSecurityDescriptor, &ftLastWriteTime);
if (cSubKeys)
{
wprintf(TEXT("\nNumber of email accounts used: %d\n"), cSubKeys);
for (i = 0; i < cSubKeys; i++)
{
cbName = MAX_KEY_LENGTH;
retCode = RegEnumKeyEx(key, i,
achKey,
&cbName,
NULL,
NULL,
NULL,
&ftLastWriteTime);
if (retCode == ERROR_SUCCESS)
{
wprintf(TEXT("(%d) %s\n"), i + 1, achKey);
}
}
}
}
}
Points of Interest
When it comes to desktop applications used for email (i.e., MAPI clients), the place to look in order to enumerate these clients, is the:
Software\Clients\Mail Key in HKEY_LOCAL_MACHINE.
There, you will find all the installed MAPI clients.
You can also determine the default one by looking at:
HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail\Default.