示例#1
0
        public static IShellLink Create(string folderPath, string name, string target, string description = "", string arguments = "", string workingDirectory = "", string iconPath = "", int iconIndex = -1)
        {
            var shortcut = new ShellLink() as IShellLink;

            if (shortcut != null && !string.IsNullOrEmpty(target) && !string.IsNullOrEmpty(name))
            {
                // setup shortcut information
                shortcut.SetPath(target);
                if (!string.IsNullOrEmpty(description))
                {
                    shortcut.SetDescription(description);
                }
                if (!string.IsNullOrEmpty(iconPath) && iconIndex >= 0)
                {
                    shortcut.SetIconLocation(iconPath, iconIndex);
                }
                if (!string.IsNullOrEmpty(arguments))
                {
                    shortcut.SetArguments(arguments);
                }
                if (!string.IsNullOrEmpty(workingDirectory))
                {
                    shortcut.SetWorkingDirectory(workingDirectory);
                }

                // save it
                var file = (IPersistFile)shortcut;
                if (!name.EndsWith(".lnk"))
                {
                    name += ".lnk";
                }
                file.Save(Path.Combine(folderPath, name), false);
            }
            return(shortcut);
        }
示例#2
0
文件: F.cs 项目: trondr/FiveChecks
        public static Option <string> CreateShortcut(Some <string> shortcutPath, Some <string> path,
                                                     Option <string> arguments, Some <string> description, bool force)
        {
            if (File.Exists(shortcutPath.Value) && !force)
            {
                return(new Option <string>(shortcutPath));
            }
            if (File.Exists(shortcutPath.Value))
            {
                File.Delete(shortcutPath.Value);
            }

            // ReSharper disable once SuspiciousTypeConversion.Global
            var link = new ShellLink() as IShellLink;

            // setup shortcut information
            link?.SetDescription(description.Value);
            link?.SetPath(path.Value);
            arguments.IfSome(a => link?.SetArguments(a));
            // save it
            // ReSharper disable once SuspiciousTypeConversion.Global
            var file = link as IPersistFile;

            file?.Save(shortcutPath, false);
            return(!File.Exists(shortcutPath.Value) ? Option <string> .None : new Option <string>(shortcutPath));
        }
示例#3
0
      public string CreateShortcut(string shortcutFilePath, string shortcutTargetPath, string description)
      {
          var link = new ShellLink() as IShellLink;

          link.SetDescription(description);
          link.SetPath(shortcutTargetPath);

          var file = link as IPersistFile;

          var shortcutLinkFilePath = this.ShortcutPathConventions.MakeFilePathIntoLinkFilePath(shortcutFilePath);

          file.Save(shortcutLinkFilePath, false);

          return(shortcutFilePath);
      }
        public static void CreateShortcutByCom(string shortcutPath, string targetPath, string iconPath, string description = null)
        {
            IShellLink link = new ShellLink() as IShellLink;

            if (link == null)
            {
                return;
            }

            link.SetDescription(description);
            link.SetPath(targetPath);
            link.SetIconLocation(iconPath, 5);
            // Convert from Keys string value to IShellLink 16-bit format
            // IShellLink: 0xMMVK
            //   MM = Modifier (Alt, Control, Shift)
            //   VK = Virtual key code
            //

            IPersistFile file = (IPersistFile)link;

            file.Save(shortcutPath, false);
            Marshal.ReleaseComObject(file);
            Marshal.ReleaseComObject(link);
        }