Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# windows 10“开始”菜单的自定义文件夹图标不存在_C#_.net_Windows - Fatal编程技术网

C# windows 10“开始”菜单的自定义文件夹图标不存在

C# windows 10“开始”菜单的自定义文件夹图标不存在,c#,.net,windows,C#,.net,Windows,我有一个应用程序,正在尝试在windows“开始”菜单中为其创建快捷方式。我正在“开始”菜单中的文件夹中创建快捷方式。该文件夹应使用dll中的自定义图标创建。此代码在windows 7中有效,但在windows 10中无效。下面是我的代码- using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Ta

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

    }
}

上述代码的问题是在Windows7中,它工作正常。即使在windows 10中的startmenu(C:/users/appdata../startmenu)位置,它也是使用自定义图标创建的。但在“开始”菜单视图中,默认文件夹图标即将出现。有什么想法吗?

我对该主题进行了进一步研究,发现windows 10的“开始”菜单仅显示默认图标。但是,如果文件夹固定在“开始”菜单平铺上,自定义图标将正确显示。

我对该主题进行了进一步研究,发现windows 10“开始”菜单仅显示默认图标。但是,如果文件夹固定在“开始”菜单平铺上,自定义图标将正确显示