1

I'm having hard times figuring out why this doesn't work on my computer. I've read this article http://msdn.microsoft.com/en-us/library/bb776820.aspx and tried it, and it works for an unknown file type, but for know such as .bmp it doesn't - I've also deleted other keys under .bmp - didn't help. I've tried this in HKEY_CLASSES_ROOT.bmp and in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.bmp I need to implement this in my program so it has custom context menu items on some file types like bmp. btw. I've tried ContextEdit (a freeware program) - also didn't work - any ideas? Maybe something not refreshing (I've tried to reboot - didn't make any changes)?

edit: One update - if I go under Set Default Programs and Windows Photo Viewer for some reason I can't disable it for some file types like .jpg, .bmp, .gif. That's strange...

edit no. 2: now it started working and I have determined the problem - the file associations didn't refresh even after restarting my computer. After I had associated a txt file to a different editor my .bmp menus, icon and default program have changed. So the main question now is - how do I manually refresh file associations using C#?

Eamonn McEvoy
  • 8,876
  • 14
  • 53
  • 83
n1tr0
  • 269
  • 4
  • 15
  • Are you trying to change behavior of short cut menu certain types of file extensions? If so make a change in Explorer->Tools->Folder Options->Advanced and a unique name like ZEBRA001 and then look up that name in regedit and see what changed. – RetroCoder Nov 09 '11 at 00:40
  • Yeah, but the problem here is that you don't have file types in Windows 7 under folder options or anywhere else. As for freeware apps that do that - they did it like in article described and it works for a new file type, and for old (even if you do it manually like in the article) it doesn't work. So I presume there are some other values needed to be changed... – n1tr0 Nov 09 '11 at 00:50

1 Answers1

2

I think I've found a solution for this one, and it goes like this - define:

    [DllImport("shell32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);

    const uint SHCNF_IDLIST = 0x0;
    const uint SHCNE_ASSOCCHANGED = 0x08000000;

Then do your code stuff with associations when needed, and after it execute:

    SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);

Also if mentioned registry keys don't work try:

    HKEY_CLASSES_ROOT\SystemFileAssociations\extension\Shell\yourcommand
n1tr0
  • 269
  • 4
  • 15
  • Don't know why but `HKEY_CLASSES_ROOT\SystemFileAssociations` doesn't exist in my machine. – ST3 Dec 23 '13 at 08:42