/* * how to use? * Shortcut.AddFavorites("http://blog.csdn.net/testcs_dn", "初学VC记录点滴", null, AppDomain.CurrentDomain.BaseDirectory + "favicon.ico") */ public static bool AddFavorites(string url, string description, string folderName, string iconLocation, string workingDirectory) { if (string.IsNullOrEmpty(workingDirectory)) { workingDirectory = ShortCutHelper.GetProgramsDir(); } string shortcutPath = ShortCutHelper.GetFavoriteDir(); if (!string.IsNullOrEmpty(folderName)) { shortcutPath += "\\" + folderName; if (!System.IO.Directory.Exists(shortcutPath)) { try { System.IO.Directory.CreateDirectory(shortcutPath); } catch //(System.Exception ex) { return(false); } } } shortcutPath += "\\" + description + ".lnk"; return(ShortCutHelper.CreateShortcut(shortcutPath, url, workingDirectory, description, iconLocation)); }
private void AddToView(string[] files, System.Collections.ArrayList al) { FileInfo fi = null; string ParentPath = string.Empty; string ExePath = string.Empty; Icon icon = null; int index = imglMenu.Images.Count; ListViewItem item = null; int j = 0; string groupKeyName = string.Empty; foreach (String srcFileName in files) { fi = new FileInfo(srcFileName); if (fi.Extension.ToLower() == ".lnk") { ParentPath = ShortCutHelper.GetParentPathOfShortcut(srcFileName); if (PubData.GV_CreateShowcutWithDel == true) { System.IO.File.Delete(srcFileName); } } else { ParentPath = srcFileName; } //if (ExistExePath(ParentPath) == false) //{ SaveExePathToDB(al, ParentPath); ExePath = ParentPath; fi = new FileInfo(ExePath); groupKeyName = fi.Extension; if (!htListGroups.Contains(groupKeyName)) { ListViewGroup group = new ListViewGroup(); group.Header = groupKeyName; group.Name = groupKeyName; lvStartMenu.Groups.Add(group); htListGroups.Add(groupKeyName, group); } icon = FileIcon.ExtractAssociatedIcon(ExePath); imglMenu.Images.Add(icon); imglMenu.Images.SetKeyName(index + j, fi.Name); item = new ListViewItem(); item.Text = fi.Name; item.Group = (ListViewGroup)htListGroups[groupKeyName]; item.Tag = fi.FullName; item.ImageIndex = index + j; lvStartMenu.Items.Add(item); j++; //} } }
/// <summary> /// 创建桌面快捷方式 /// </summary> /// <param name="targetPath">可执行文件路径</param> /// <param name="description">快捷方式名称</param> /// <param name="iconLocation">快捷方式图标路径</param> /// <param name="workingDirectory">工作路径</param> /// <returns></returns> public static bool CreateDesktopShortcut(string targetPath, string description, string iconLocation, string workingDirectory) { if (string.IsNullOrEmpty(workingDirectory)) { workingDirectory = ShortCutHelper.GetDeskDir(); } return(ShortCutHelper.CreateShortcut(ShortCutHelper.GetDeskDir() + "\\" + description + ".lnk", targetPath, workingDirectory, description, iconLocation)); }
private void tsmiCreateShortCutOnUtil_Click(object sender, EventArgs e) { if (lvUtilSofeware.SelectedItems.Count > 0) { string exePath = lvUtilSofeware.SelectedItems[0].Tag.ToString(); string sFilename = exePath; string sFile = DirFile.GetFileNameNoExtension(sFilename); string sShortcutPath = ShortCutHelper.GetDeskDir() + "\\" + sFile + ".lnk"; if (!System.IO.File.Exists(sShortcutPath)) { string sWorkPath = DirFile.GetLastDirectory(sFilename); //创建快捷键 ShortCutHelper.CreateShortcut(sShortcutPath, sFilename, sWorkPath, "Make In IRunner", ""); } } }
private void tsmiCreateShortCut_Click(object sender, EventArgs e) { if (mouseDownOnListview != Point.Empty) { ListViewHitTestInfo info = lvStartMenu.HitTest(mouseDownOnListview.X, mouseDownOnListview.Y); if (info.Item != null && info.Item.Group != null) { string sFilename = info.Item.Tag.ToString(); string sFile = DirFile.GetFileNameNoExtension(sFilename); string sShortcutPath = ShortCutHelper.GetDeskDir() + "\\" + sFile + ".lnk"; if (!System.IO.File.Exists(sShortcutPath)) { string sWorkPath = DirFile.GetLastDirectory(sFilename); //创建快捷键 ShortCutHelper.CreateShortcut(sShortcutPath, sFilename, sWorkPath, "Make In IRunner", ""); } } } }