Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Associating file extensions with programs

Status
Not open for further replies.

Pyramus

Programmer
Dec 19, 2001
237
0
0
GB
How do you go about setting which program runs a particular file extension? So for example, I want program.exe to launch whenever a file with extension .ext is run. Is this info in the registry somewhere?
 
You could set the program that is associated with a particular file extension in the folder options menu item of the windows explorer, if that is what you mean.
srfink
 
Given that I'm posting in the C++ forum, I'm quite obviously looking for a programatic explanation.
 
OK. Here's an example of how you could do it programatically:
// The following code snippet sets the file program
// that is associated with the cnf extension to WORDPAD
char szProductType[80];
DWORD dwBufLen;
HKEY hTestKey = NULL;
LONG lResult = ::RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.cnf\\OpenWithList", 0,
KEY_ALL_ACCESS, &hTestKey);
if ((ERROR_SUCCESS == lResult) && (hTestKey != NULL))
{
strcpy(szProductType,"WORDPAD.exe");
lResult = RegSetValueEx(hTestKey, "a", NULL, REG_SZ, (LPBYTE) szProductType, dwBufLen);
RegCloseKey(hTestKey);
}
Hows this?
happy.gif

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top