簡體   English   中英

Windows 10開始菜單的自定義文件夾圖標未來

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

我有一個應用程序,我試圖在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中它工作正常。 即使在startmenu(C:/ users / appdata ../ StartMenu)位置的Windows 10中,也會使用自定義圖標創建它。但是在開始菜單視圖中,默認文件夾圖標即將到來。任何想法?

我對該主題進行了更多研究,發現Windows 10“開始”菜單僅顯示默認圖標。但是,如果文件夾固定到“開始菜單”圖塊,則自定義圖標會正確顯示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM