- PR -

Windowsフォルダアイコンの変更

投稿者投稿内容
Jitta
ぬし
会議室デビュー日: 2002/07/05
投稿数: 6267
お住まい・勤務地: 兵庫県・海手
投稿日時: 2006-06-12 21:45
試してください。(つまり、未検証)
コード:
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);
	}
}

ひろひろ
常連さん
会議室デビュー日: 2004/07/23
投稿数: 36
投稿日時: 2006-06-13 21:00
>Jittaさん
サンプルコードの提供ありがとうございます。

これで動作させてみたところ、やりたいことを達成できました。

ありがとうございます。

スキルアップ/キャリアアップ(JOB@IT)