如何使用C#从Windows中的Startmenu中删除快捷方式文件夹,我知道如何使用此代码执行此操作:
private void RemoveShortCutFolder(string folder) { folder = folder.Replace("\" ", ""); folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), folder); try { if (System.IO.Directory.Exists(folder)) { System.IO.Directory.Delete(folder, true); } else { } } catch (Exception) { } }
但是我需要删除ALL USERS文件夹中的一个快捷方式文件夹而不是当前登录用户的问题.Environment.SpecialFolder.StartMenu为我提供了当前用户并非所有用户文件夹.
任何的想法,
谢谢,
如果你不介意一点Win32,你可以使用SHGetSpecialFolderPath
.
[DllImport("shell32.dll")] static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, StringBuilder lpszPath, CSIDL nFolder, bool fCreate); enum CSIDL { COMMON_STARTMENU = 0x0016, COMMON_PROGRAMS = 0x0017 } static void Main(string[] args) { StringBuilder allUsersStartMenu = new StringBuilder(255); SHGetSpecialFolderPath(IntPtr.Zero, allUsersStartMenu, CSIDL.COMMON_PROGRAMS, false); Console.WriteLine("All Users' Start Menu is in {0}", allUsersStartMenu.ToString()); }