Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an application for which I am trying to create a shortcut in the windows Start menu.I am creating a shortcut in a folder inside start menu.The folder should be created with my custom icon which is present in a dll.This code works in windows 7 but not in windows 10.Below is my code-


C#
 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);
        }        

    }
}



C#
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?


What I have tried:

I have tried killing the explorer and restarting it in case of it is a refreshing problem.But it did not work.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900