class Program { static void Main(string[] args) { string pathToExe = @"D:\Practice\folder\nipp.exe"; string commonStartMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); string[] resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames(); string appStartMenuPath = Path.Combine(commonStartMenuPath, "Programs", "Custom_folder"); if (!Directory.Exists(appStartMenuPath)) Directory.CreateDirectory(appStartMenuPath); setFolderIcon(appStartMenuPath,"my folder"); string shortcutLocation = Path.Combine(appStartMenuPath, "Shortcut_to_Test_App" + ".lnk"); WshShell shell = new WshShell(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation); shortcut.Description = "Test App Description"; shortcut.TargetPath = pathToExe; shortcut.Save(); Console.WriteLine("Done"); Console.ReadLine(); } public static void setFolderIcon(string path, string folderToolTip) { /* Remove any existing desktop.ini */ if (System.IO.File.Exists(path + @"\desktop.ini")) System.IO.File.Delete(path + @"\desktop.ini"); /* Write the desktop.ini */ using (StreamWriter sw = System.IO.File.CreateText(path + @"\desktop.ini")) { sw.WriteLine("[.ShellClassInfo]"); sw.WriteLine("InfoTip=" + folderToolTip); sw.WriteLine("IconFile=" + @"C:\Program Files (x86)\blah\blah\abc.dll"); sw.WriteLine("IconIndex=-101"); } /* Set the desktop.ini to be hidden */ System.IO.File.SetAttributes(path + @"\desktop.ini", System.IO.File.GetAttributes(path + @"\desktop.ini") | FileAttributes.Hidden); /* Set the path to system */ System.IO.File.SetAttributes(path, System.IO.File.GetAttributes(path) | FileAttributes.System); } } }
The problem with the above code is in windows 7 it is working fine. Even in windows 10 in the location of startmenu(C:/users/appdata../StartMenu) it is getting created with custom icon.But in the start menu view the default folder icon is coming.Any ideas?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)