Beispiel #1
0
        /// <summary>Modifies properties of an existing lnk/url shortcut link, like target path, arguments etc. (* for Urls).</summary>
        /// <param name="shortcut">The full path of an existing lnk/url shortcut link file.</param>
        /// <param name="target">* The full path of the target file/-folder resp. URL address.</param>
        /// <param name="args">Startparameter when launching the shortcut or "" (for url).</param>
        /// <param name="folder">The full path of the start folder or "" (for url).</param>
        /// <param name="desc">* Comment or description for the shortcut or "".</param>
        /// <param name="icoPath">* Full path of the icon file for the shortcut or "".</param>
        /// <param name="icoIdx">* Index of the icon in the icon file (default: 0, for .ico).</param>
        /// <param name="hotkey">* keys combination to launch the shortcut link (default: 0).</param>
        /// <param name="style">* Window style when launching the shortcut (default: 1 normal, 3 max, 7 min).</param>
        /// <returns>The full file path of the modified shortcut on success, else "FAILED".</returns>
        public static Primitive LinkSetProperty(Primitive shortcut, Primitive target, Primitive args, Primitive folder, Primitive desc, Primitive icoPath, Primitive icoIdx, Primitive hotkey, Primitive style)
        {
            string scPath = Environment.ExpandEnvironmentVariables(shortcut);

            if (!System.IO.File.Exists(scPath))
            {
                return("FAILED");
            }
            else
            {
                string scDir      = Path.GetDirectoryName(scPath);
                string scFNameExt = Path.GetFileName(scPath);

                Shell32.Folder     fold     = GetShell32NameSpace(scDir);
                Shell32.FolderItem foldItem = fold.ParseName(scFNameExt);
                try
                {
                    Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)foldItem.GetLink;
                    link.Path             = target;
                    link.Arguments        = args;
                    link.WorkingDirectory = folder;
                    link.Description      = desc;
                    link.Hotkey           = hotkey;
                    link.ShowCommand      = style;
                    link.SetIconLocation(icoPath, icoIdx);
                    link.Save(scPath);
                    return(scPath);
                }
                catch
                { return("FAILED"); }
            }
        }
Beispiel #2
0
        /// <summary>Creates a new lnk/url shortcut (Shell32). Further editing with 'LinkSetProperty'.</summary>
        /// <param name="shortcut">The full path for the new lnk/url shortcut file.</param>
        /// <param name="target">The full path of the target file/-folder resp. URL address.</param>
        /// <returns>The full file path of the created shortcut on success, else "FAILED".</returns>
        public static Primitive LinkCreate(Primitive shortcut, Primitive target)
        {
            if (String.IsNullOrEmpty(target))
            {
                return("FAILED");
            }
            string scPath = Environment.ExpandEnvironmentVariables(shortcut);
            string scDir  = Path.GetDirectoryName(scPath);

            if (!Directory.Exists(scDir))
            {
                return("FAILED");
            }
            string scFNameExt = Path.GetFileName(scPath);

            try
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(scPath, false);
                sw.Close();

                Shell32.Folder          fold     = GetShell32NameSpace(scDir);
                Shell32.FolderItem      foldItem = fold.ParseName(scFNameExt);
                Shell32.ShellLinkObject link     = (Shell32.ShellLinkObject)foldItem.GetLink;

                link.Path = target;
                link.Save(scPath);
                return(scPath);
            }
            catch
            { return("FAILED"); }
        }
Beispiel #3
0
        /// <summary>Gets properties of a lnk/url shortcut link, like target pfad, arguments etc.</summary>
        /// <param name="shortcut">The full path of the lnk/url shortcut link file.</param>
        /// <param name="property">The property to get (case independent, * for Urls) like:
        /// "Target"  target path *
        /// "Args"    arguments
        /// "Folder"  working directory
        /// "Desc"    comment *
        /// "HotKey"  shortcut key comb * (default: 0)
        /// "Style"   window style * (1 normal, 3 max, 7 min)
        /// "Icon"    icon path</param>
        /// <returns>The value of the property if available or "". "FAILED" on failure.</returns>
        public static Primitive LinkGetProperty(Primitive shortcut, Primitive property)
        {
            string scPath = Environment.ExpandEnvironmentVariables(shortcut);

            if (!System.IO.File.Exists(scPath))
            {
                return("FAILED");
            }
            string prop = property;
            string nIcon;
            int    icoIdx     = 0;
            string scDir      = Path.GetDirectoryName(scPath);
            string scFNameExt = Path.GetFileName(scPath);

            try
            {
                Shell32.Folder          fold     = GetShell32NameSpace(scDir);
                Shell32.FolderItem      foldItem = fold.ParseName(scFNameExt);
                Shell32.ShellLinkObject link     = (Shell32.ShellLinkObject)foldItem.GetLink;
                switch (prop.ToUpper())
                {
                case "TARGET": return(link.Path);

                case "ARGS": return(link.Arguments);

                case "FOLDER": return(link.WorkingDirectory);

                case "DESC": return(link.Description);

                case "HOTKEY": return(link.Hotkey);

                case "STYLE": return(link.ShowCommand);

                case "ICON":
                {
                    icoIdx = link.GetIconLocation(out nIcon);
                    return(nIcon + "," + icoIdx.ToString());
                }

                default: return("FAILED");
                }
            }
            catch
            { return("FAILED"); }
        }