Beispiel #1
0
        public static bool AddFavorites(string url, string description, string folderName, string iconLocation = null, string workingDirectory = null)
        {
            if (string.IsNullOrEmpty(workingDirectory))
            {
                workingDirectory = ShortcutUtil.GetProgramsDir();
            }
            string shortcutPath = ShortcutUtil.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(ShortcutUtil.CreateShortcut(shortcutPath, url, workingDirectory, description, iconLocation));
        }
Beispiel #2
0
 /// <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 = null, string workingDirectory = null)
 {
     if (string.IsNullOrEmpty(workingDirectory))
     {
         workingDirectory = ShortcutUtil.GetCurrentUserDeskDir();
     }
     return(ShortcutUtil.CreateShortcut(ShortcutUtil.GetCurrentUserDeskDir() + "\\" + description + ".lnk", targetPath, workingDirectory, description, iconLocation));
 }