简体   繁体   English

Windows 10开始菜单的自定义文件夹图标未来

[英]Custom folder icon for windows 10 start menu is not coming

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- 我有一个应用程序,我试图在Windows开始菜单中创建一个快捷方式。我在开始菜单中的文件夹中创建一个快捷方式。应该使用我的自定义图标创建文件夹,该图标存在于dll中。此代码有效在Windows 7中但不在Windows 10中。下面是我的代码 -

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Threading.Tasks;
using IWshRuntimeLibrary;
using System.Diagnostics;
using System.Reflection;
using System.Drawing;

namespace CreateDesktopShortCut
{
    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. 上面的代码的问题是在Windows 7中它工作正常。 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? 即使在startmenu(C:/ users / appdata ../ StartMenu)位置的Windows 10中,也会使用自定义图标创建它。但是在开始菜单视图中,默认文件夹图标即将到来。任何想法?

我对该主题进行了更多研究,发现Windows 10“开始”菜单仅显示默认图标。但是,如果文件夹固定到“开始菜单”图块,则自定义图标会正确显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM