【问题标题】:Custom folder icon for windows 10 start menu is not comingWindows 10 开始菜单的自定义文件夹图标未出现
【发布时间】:2017-06-12 16:29:38
【问题描述】:

我有一个应用程序,我正在尝试在 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);
        }        

    }
}

上述代码的问题在于 Windows 7 运行良好。即使在 Windows 10 的 startmenu(C:/users/appdata../StartMenu) 位置,它也是使用自定义图标创建的。但是在开始菜单视图中,默认文件夹图标即将出现。有什么想法吗?

【问题讨论】:

    标签: c# .net windows


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-19
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多