Пример #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);
        }