获取系统当前默认浏览器
win XP
HKEY_CLASSES_ROOT\HTTP\shell\open\command 键值下 Default 默认值是 "C:\Program Files\Internet Explorer\iexplore.exe" -nohome
win7
HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\Ftp\UserChoice键值下Progid的值,如果是IE浏览器的话,将在HKEY_CLASSES_ROOT\IE.FTP\shell\open\command下获取到,在win7下的获取程序如下:
void LaunchDefaultBrowser()
{
HKEY hDefBrowserPos = NULL;
wstring wstrDefBrowserPath = L"iexplore.exe";
WCHAR wszBuffer[MAX_PATH + 1] = {0};
DWORD dwDataSize = sizeof(wszBuffer);
if (ERROR_SUCCESS == ::RegGetValueW(
HKEY_CURRENT_USER,
L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\Ftp\\UserChoice\\",
L"Progid",
RRF_RT_REG_SZ,
0,
wszBuffer,
&dwDataSize
))
{
wstring wstrDefBrowserPos = wszBuffer;
wstrDefBrowserPos += L"\\shell\\open\\command\\";
dwDataSize = sizeof(wszBuffer);
if (ERROR_SUCCESS == ::RegGetValueW(
HKEY_CLASSES_ROOT,
wstrDefBrowserPos.c_str(),
NULL,
RRF_RT_REG_SZ,
0,
wszBuffer,
&dwDataSize
))
{
// 解出exe 路径.
wstrDefBrowserPath = wszBuffer;
wstring::size_type leftQuotation = wstrDefBrowserPath.find(L'"');
if (leftQuotation != wstring::npos)
{
wstring::size_type rightQuotation = wstrDefBrowserPath.find(L'"', leftQuotation + 1);
if (rightQuotation != wstring::npos)
{
wstrDefBrowserPath.assign(
wstrDefBrowserPath.begin() + leftQuotation + 1,
wstrDefBrowserPath.begin() + rightQuotation
);
}
}
}
}
::ShellExecuteW(
NULL,
L"open",
wstrDefBrowserPath.c_str(),
NULL,
NULL,
SW_NORMAL
);
}
貌似win7下的也和xp一样,在root下面有相应的值对应,可查看到当前的浏览器目录
HKEY key = NULL;
CHAR szXplorer[BUFSIZE];
DWORD dwBufLen;
DWORD type = REG_SZ;
ZeroMemory(szXplorer,BUFSIZE);
if(ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CLASSES_ROOT,
"http\\shell\\open\\command",
0,
KEY_QUERY_VALUE,
&key))
{
LONG lRet;
lRet = ::RegQueryValueEx(key,NULL,NULL,&type,(LPBYTE)szXplorer,&dwBufLen);
if(lRet == ERROR_SUCCESS)
printf("Default Explore is: %s",szXplorer);
RegCloseKey(key);
}