質問するログイン新規登録

回答編集履歴

1

追記

2017/03/06 06:58

投稿

YAmaGNZ
YAmaGNZ

スコア10688

answer CHANGED
@@ -1,2 +1,39 @@
1
1
  [Windowsフォルダアイコンの変更](http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=31235&forum=7)
2
- このような情報がありました。
2
+ このような情報がありました。
3
+
4
+
5
+ ・追記
6
+
7
+ リンク先のコードを試してみました。
8
+ ```C#
9
+ public class SetFolderIcon
10
+ {
11
+ [DllImport("kernel32.dll")]
12
+ private static extern bool WritePrivateProfileString(
13
+ string lpAppName, string lpKeyName
14
+ , string lpString, string lpFileName);
15
+ [DllImport("shlwapi.dll")]
16
+ private static extern bool PathMakeSystemFolder(
17
+ string folderName);
18
+
19
+ private SetFolderIcon()
20
+ {
21
+ }
22
+
23
+ public static void SetIcon(string targetFolder, string iconFilePath, int iconIndex)
24
+ {
25
+ string desktopIni = System.IO.Path.Combine(targetFolder, "Desktop.ini");
26
+ WritePrivateProfileString(".ShellClassInfo", "IconFile", iconFilePath, desktopIni);
27
+ WritePrivateProfileString(".ShellClassInfo", "IconIndex", iconIndex.ToString(), desktopIni);
28
+ System.IO.FileInfo finfo = new System.IO.FileInfo(desktopIni);
29
+ finfo.Attributes |= System.IO.FileAttributes.Hidden;
30
+ PathMakeSystemFolder(targetFolder);
31
+ }
32
+ }
33
+
34
+ ```
35
+ として
36
+ ```C#
37
+ SetFolderIcon.SetIcon(フォルダパス, アイコンファイル名, 0);
38
+ ```
39
+ としたところアイコンは変更されました。