To programatically change the icon of a folder, I found that I need to set the folder's attribute to be a system folder.
Guide I worked with: http://www.codeproject.com/Articles/9331/Create-Icons-for-Folders-in-Windows-Explorer-Using
And the relevant code:
File.SetAttributes(folderPath, File.GetAttributes(folderPath) | FileAttributes.System);
Looking at the documentation, this function should have thrown an exception for a folder path as parameter:
https://msdn.microsoft.com/en-us/library/system.io.file.setattributes%28v=vs.110%29.aspx
Is this really the correct API?
In addition, what are the consequences of setting it as a system folder?
SetFileAttributes function works both on files and directories, and File.SetAttributes calls it underneath. So it's the correct API. I see no mentioning of raising exceptions on folders. There is one if the path to the folder is on network drive, but that just means that the function accepts folders, just not bad folders.
As for setting the folder attribute to system, it's arguably less annoying if it's set to read-only. The effect is the same.