我有一个应用程序,我试图在Windows开始菜单中创建一个快捷方式。我在开始菜单中的文件夹中创建一个快捷方式。应该使用我的自定义图标创建文件夹,该图标存在于dll中。此代码适用于Windows 7,但不适用于Windows 10.Below是我的代码 -
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中,也会使用自定义图标创建它。但是在开始菜单视图中,默认文件夹图标即将到来。有什么想法吗?
答案 0 :(得分:0)
我对该主题进行了更多研究,发现Windows 10“开始”菜单仅显示默认图标。但是,如果文件夹固定到“开始菜单”图块,则自定义图标会正确显示。