using System;
using System.Runtime.InteropServices;
public class SetFolderIcon
{
[DllImport("kernel32.dll")]
private static extern bool WritePrivateProfileString(
string lpAppName, string lpKeyName
, string lpString, string lpFileName);
[DllImport("shlwapi.dll")]
private static extern bool PathMakeSystemFolder(
string folderName);
private SetFolderIcon()
{
}
public static void SetIcon(string targetFolder, string iconFilePath, int iconIndex)
{
string desktopIni = System.IO.Path.Combine(targetFolder, "Desktop.ini");
WritePrivateProfileString(".ShellClassInfo", "IconFile", iconFilePath, desktopIni);
WritePrivateProfileString(".ShellClassInfo", "IconIndex", iconIndex.ToString(), desktopIni);
System.IO.FileInfo finfo = new System.IO.FileInfo(desktopIni);
finfo.Attributes |= System.IO.FileAttributes.Hidden;
PathMakeSystemFolder(targetFolder);
}
}
|