Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Intermediate
Jun 17, 2008

How to Determine the Default Web Browser

Sometimes people assume that the default web browser is the program that is registered in the Windows registry to open files with an .html extension. However, it's possible to set a default program to open .html files and another to open URL links that use the HTTP protocol.

The code below determines the default web browser for the HTTP protocol:


DWORD size = 256; HKEY hKey; int i, pos, len;
TCHAR browserProgram[512], TCHAR buf[256];
TCHAR *exeExtension = ".exe"; 
RegOpenKeyEx(HKEY_CLASSES_ROOT, _TEXT("http\\shell\\open\\command"), 
 0, KEY_QUERY_VALUE, &hKey);
RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)buf, &size);
RegCloseKey(hKey); 
if (buf[0] == _TEXT('\"'))
 lstrcpy(browserProgram, &buf[1]);
else
 lstrcpy(browserProgram, buf);
len = lstrlen(browserProgram);
pos = len - 4;
for (i = 0; i < len - 3; i++)
 if (!strnicmp(&browserProgram[i], exeExtension, 4))
 {
  pos = i; break;
 }
browserProgram[pos + 4] = _TEXT('\0');
std::cout << browserProgram << std::endl;

Alexander Ocher
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap