Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Application Security Testing: An Integral Part of DevOps

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);
if (buf[0] == _TEXT('\"'))
 lstrcpy(browserProgram, &buf[1]);
 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.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date