Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh the folder icon instantly in Windows

Tags:

c++

c

winapi

I am now programming a small tool and need to refresh the folder icon instantly.
As we know, in Windows, we could modify folder icons by the following steps manually:

  1. right click the folder
  2. choose "customize" tag
  3. click "change icon"

I also know how to set the desktop.ini file to modify its icon. But it takes really a long time to refresh (about 30 seconds).

I wanna know if there is a common way to solve it instantly no matter using C/C++ or script. Or Windows never provides a way?

like image 253
Neko Gong Avatar asked Dec 19 '25 11:12

Neko Gong


1 Answers

This small C program will do the job:

#include <windows.h>
#include <ShlObj.h>

const char folderpath[] = "C:\\Your-Folder";

int main() {
  SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, folderPath, NULL);
}

folderpath is the full path to the folder whose icon is to be updated Following sequence of operations works fine here (Windows 10 64 bits):

Desktop.ini file

[.ShellClassInfo]
IconResource=C:\Windows\System32\SHELL32.dll,12
  1. Create a folder X
  2. Copy the Desktop.ini file above into the folder. The icon of the X folder will not change
  3. Run the small C program above
  4. The new icon is displayed on the X folder
  5. Remove the Deskop.ini file created at point 2. The icon of the X folder will not change
  6. Run the small C program above
  7. The original folder icon is displayed on the X folder

Check the SHChangeNotify function for more details.

like image 96
Jabberwocky Avatar answered Dec 21 '25 03:12

Jabberwocky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!