9

I've been trying to change folder icon programmatically using changing desktop.ini on the folder. I was able to set an icon, but couldn't change it immediately through changing "IconIndex". The icon was also changed in a few seconds later.

Is there anybody know how to change the icon immediately?

4
  • 3
    Take a look SHChangeNotify API and lookup related SO posts.
    – 9dan
    Jun 24, 2011 at 6:39
  • 1
    I have found a solution about own question. That's what it use SHGetSetFolderCustomSettings Win32 function. Jun 25, 2011 at 18:01
  • 2
    You may write it up as a complete answer below.. That will make it easier for the visitors of this question and it(your answer) will be voted up as well. Aug 17, 2012 at 20:02
  • Can't use SHGetSetFolderCustomSettings in Windows 10. any workaround?
    – Elron
    Aug 26, 2021 at 10:10

3 Answers 3

1

I already answered by commenting a reply at my question before. For more convenience, I will write an answer again.

If you want to make any change at an appearance of any folder using Desktop.ini, use some of win32 shell functions. You shouldn't try to edit a Desktop.ini directly. It doesn't get to make any change at an appearance of any folder.

You could get more information of win32 shell functions through the following link.

http://msdn.microsoft.com/en-us/library/windows/desktop/bb776426(v=vs.85).aspx

1

Example:

SHFOLDERCUSTOMSETTINGS fcs = {0};
fcs.dwSize = sizeof(SHFOLDERCUSTOMSETTINGS);
fcs.dwMask = FCSM_ICONFILE;
fcs.pszIconFile = iconPath;
fcs.cchIconFile = 0;
fcs.iIconIndex = iconIndex;
SHGetSetFolderCustomSettings(&fcs, folderPath, FCS_FORCEWRITE);
1
  • I get an error: 'SHFOLDERCUSTOMSETTINGS' was not declared in this scope. any workaround? same goes for 'SHGetSetFolderCustomSettings' was not declared in this scope
    – Elron
    Aug 26, 2021 at 11:48
0

The following procedure works well for me (on Windows 7):

  1. Change desktop.ini file
  2. Issue SHChangeNotify(SHCNE_DELETE,SHCNF_PATH,"path_to/desktop.ini",0);
  3. Folder ico will be refreshed

Remember to include Shlobj.h

3
  • Wrong include. It should be Shlwapi.h. Jul 26, 2015 at 23:22
  • NO it doesn't work at all. 5 hour in computer during the night works as mirage Jul 27, 2015 at 5:54
  • Any Idea How to refresh folder icons after desktop.ini change? The SHGetSetFolderCustomSettings is not suported since XP windows. Jul 27, 2015 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.