MFC: File Association

Dear experts,

I have an MFC application. The user can check for update, then (if an update is needed)  a new executable with a different name is downloaded. I want now to associate documents that the application opens, with the new executable. I found a web site that provides an example how to reset file association:
http://www.codeproject.com/KB/shell/cgfiletype.aspx
But though a new entry is added in the registry, nothing changes, and the document is still opened with an old version of the program, and the icon in the Windows Explorer looks like before.
I use Windows XP, but of course I want the program to work also in the higher versions.
Could you  please tell what I am missing?
Thanks.
tantormediaAsked:
Who is Participating?
 
tantormediaConnect With a Mentor Author Commented:
Never mind, I figured it out: I had to remove Application entry in HKCU\Software\Microsoft\Windows\Current Version\Explorer\FileExts\.myext.
Thanks.
0
 
flubbsterCommented:
Try this

Open any folder
Click on Tools
Select Folder Options
Select File Types
Scroll down and file the extension that you want to associate with the new peogram
Click on Change
Click on Browse
Using the Browse window that opened, find the executable that you want to use to open that extension
Double-click the program to select it
Make sure that "Always use this program...." is checked
Click on ok/apply to back out
Test
0
 
tantormediaAuthor Commented:
Thank you very much for your answer. But I need the file association to be updated automatically, I don't want the user to do it every time an update is downloaded.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
tantormediaAuthor Commented:
I found solution for changing icons:
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);

But when I click on a document icon in the explorer, it is still opened with the old version of the program.
0
 
flubbsterCommented:
Can you paste exactly what code you used?
0
 
sarabandeCommented:
you could find out your filetype with the command line

  assoc .yourtype

it will prompt like

.yourtype=yourfiletype

then you could change or add an 'open' command for that filetype by

 ftype yourfiletype=path_to_your_exe %1

Sara
0
 
tantormediaAuthor Commented:
Thank you Sara,

This is what my program does automatically on update:

// Update file association
	CGCFileTypeAccess TheFTA;

	// get full file path to program executable file
	//TCHAR	szProgPath[MAX_PATH * 2];
	//::GetModuleFileName(NULL, szProgPath, sizeof(szProgPath)/sizeof(TCHAR));

	CString csTempText;

	TheFTA.SetExtension("bok");

	// just pass file path in quotes on command line
	csTempText.Format("\"%s\" %s", executable, "\"%1\"");

	TheFTA.SetShellOpenCommand(csTempText);
	TheFTA.SetDocumentShellOpenCommand(csTempText);

	TheFTA.SetDocumentClassName("CGFileType.Document");

	// use first icon in program
	csTempText  = executable;
	csTempText += ",0";
	TheFTA.SetDocumentDefaultIcon(csTempText);

	SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); 

	// set the necessary registry entries	
	TheFTA.RegSetAllInfo();

Open in new window

0
 
sarabandeCommented:
you might check on return codes and errors in your code.

the user must be local admin to have the rights for your code, and i wonder whether you could make updates with the code.

Sara
0
 
tantormediaAuthor Commented:
The solution is in my previous message.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.