2016-06-21 22 views
1

我有一個應用程序,我試圖在Windows開始菜單中創建一個快捷方式。我在開始菜單中的文件夾中創建一個快捷方式。應創建文件夾與存在於dll.This代碼我的自定義圖標在Windows 7但不是在Windows 10.Below工作是我的代碼 -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。即使在啓動菜單(C:/ users/appdata ../ StartMenu)的窗口10中,它也使用自定義圖標創建。但在開始菜單視圖中,默認文件夾圖標即將到來。任何想法?

回答

0

我對這個主題做了一些更多的研究,發現windows 10的開始菜單隻顯示默認的圖標。但是,如果文件夾被固定到開始菜單切片,自定義圖標就會正常顯示。

相關問題