Exemple #1
0
        internal ShortcutInfo(string path, IShellLink native)
        {
            Path = path;

            StringBuilder tmp = new StringBuilder(1024);
            
            native.GetArguments(tmp, tmp.Capacity);
            Arguments = tmp.ToString();

            native.GetDescription(tmp, tmp.Capacity);
            Description = tmp.ToString();

            native.GetIconLocation(tmp, tmp.Capacity, out IconIndex);
            IconPath = tmp.ToString();

            native.GetPath(tmp, tmp.Capacity, IntPtr.Zero, 0);
            TargetPath = tmp.ToString();

            native.GetWorkingDirectory(tmp, tmp.Capacity);
            WorkingDirectory = tmp.ToString();

            uint ws = 0;
            native.GetShowCmd(out ws);
            WindowState = (ShortcutWindowState)(ws);
        }
        /// <summary>
        /// 创建快捷方式。
        /// </summary>
        /// <param name="shortcutPath">快捷方式路径。</param>
        /// <param name="targetPath">目标路径。</param>
        /// <param name="workingDirectory">工作路径。</param>
        /// <param name="description">快捷键描述。</param>
        public static bool CreateShortcut(string shortcutPath, string targetPath, string workingDirectory, string description, string iconLocation = null)
        {
            try
            {
                CShellLink cShellLink = new CShellLink();
                IShellLink iShellLink = (IShellLink)cShellLink;
                iShellLink.SetDescription(description);
                iShellLink.SetShowCmd(SW_SHOWNORMAL);
                iShellLink.SetPath(targetPath);
                iShellLink.SetWorkingDirectory(workingDirectory);

                if (!string.IsNullOrEmpty(iconLocation))
                {
                    iShellLink.SetIconLocation(iconLocation, 0);
                }

                IPersistFile iPersistFile = (IPersistFile)iShellLink;
                iPersistFile.Save(shortcutPath, false);
                Marshal.ReleaseComObject(iPersistFile);
                iPersistFile = null;
                Marshal.ReleaseComObject(iShellLink);
                iShellLink = null;
                Marshal.ReleaseComObject(cShellLink);
                cShellLink = null;
                return(true);
            }
            catch //(System.Exception ex)
            {
                return(false);
            }
        }
Exemple #3
0
        internal ShortcutInfo(string path, IShellLink native)
        {
            Path = path;

            StringBuilder tmp = new StringBuilder(1024);

            native.GetArguments(tmp, tmp.Capacity);
            Arguments = tmp.ToString();

            native.GetDescription(tmp, tmp.Capacity);
            Description = tmp.ToString();

            native.GetIconLocation(tmp, tmp.Capacity, out IconIndex);
            IconPath = tmp.ToString();

            native.GetPath(tmp, tmp.Capacity, IntPtr.Zero, 0);
            TargetPath = tmp.ToString();

            native.GetWorkingDirectory(tmp, tmp.Capacity);
            WorkingDirectory = tmp.ToString();

            uint ws = 0;

            native.GetShowCmd(out ws);
            WindowState = (ShortcutWindowState)(ws);
        }
        private void CreateShortcut(string path)
        {
            try
            {
                IShellLink link = (IShellLink) new ShellLink();

                link.SetPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                          "LEProc.exe"));
                link.SetArguments(String.Format("-run \"{0}\"", path));
                link.SetIconLocation(AssociationReader.GetAssociatedIcon(Path.GetExtension(path)).Replace("%1", path), 0);

                link.SetDescription(string.Format("Run {0} with Locale Emulator", Path.GetFileName(path)));
                link.SetWorkingDirectory(Path.GetDirectoryName(path));

                IPersistFile file = (IPersistFile)link;
                file.Save(
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                                 Path.GetFileNameWithoutExtension(path) + ".lnk"),
                    false);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + "\r\n\r\n" + e.StackTrace);
            }
        }
Exemple #5
0
 /// <summary>
 ///     Create an empty shell link object
 /// </summary>
 public ShellLink()
 {
     theShellLinkObject = new ShellLinkCoClass();
     shellLink          = (IShellLink)theShellLinkObject;
     dataList           = (IShellLinkDataList)theShellLinkObject;
     consoleProperties  = new ConsoleProperties(this);
 }
Exemple #6
0
        public static IShellLink Create()
        {
            ShellLink  link      = new ShellLink();
            IShellLink shellLink = (IShellLink)link;

            return(shellLink);
        }
Exemple #7
0
 /// <summary>
 ///   Create an empty shell link object
 /// </summary>
 public ShellLink()
 {
     theShellLinkObject = new ShellLinkCoClass();
     shellLink = (IShellLink) theShellLinkObject;
     dataList = (IShellLinkDataList) theShellLinkObject;
     consoleProperties = new ConsoleProperties(this);
 }
Exemple #8
0
        /// <summary>Создать ярлык</summary>
        /// <param name="pathToFile">Путь к файлу на который будет создан ярлык</param>
        /// <param name="pathToLink">Путь, по которому будет создан ярлык</param>
        /// <param name="description">Описание, которое будет отображаться при наведении на ярлык</param>
        /// <param name="iconFile">Путь для иконки к ярлыку (путь к приложению)</param>
        /// <param name="iconIndex">Индекс иконки в файле приложения от нуля</param>
        /// <returns></returns>
        public static bool Create(
            string pathToFile, string pathToLink,
            string description, string iconFile, int iconIndex)
        {
            IShellLink shlLink = (IShellLink)(new ShellLink());//CreateShellLink

            Marshal.ThrowExceptionForHR(shlLink.SetIconLocation(iconFile, iconIndex));
            Marshal.ThrowExceptionForHR(shlLink.SetDescription(description));
            Marshal.ThrowExceptionForHR(shlLink.SetPath(pathToFile));

/*            if (System.IO.File.Exists(pathToLink))
 *          try
 *          {
 *              System.IO.File.Delete(pathToLink);//может бросить исключение
 *          }
 *          catch(Exception)
 *          {
 *              return false;
 *          }*/
            bool isExecutable = pathToFile.EndsWith(".exe", StringComparison.CurrentCultureIgnoreCase);

            ((System.Runtime.InteropServices.ComTypes.IPersistFile)shlLink).Save(pathToLink, isExecutable);

            return(true);
        }
Exemple #9
0
        public void Dispose()
        {
            if (this.link == null)
                return;

            Marshal.ReleaseComObject(this.link);
            this.link = null;
        }
        public static void CreateShortcut(string exepath, string lnkpath)
        {
            IShellLink link = (IShellLink) new ShellLink();

            link.SetDescription("Launch Olympus");
            link.SetPath(exepath);
            ((IPersistFile)link).Save(lnkpath, false);
        }
Exemple #11
0
        public void MakeLink(string description, IntPtr ppath, string path)
        {
            IShellLink link = (IShellLink) new ShellLink();

            link.SetIDList(ppath);
            IPersistFile file = (IPersistFile)link;

            file.Save(path, false);
        }
Exemple #12
0
        public void Dispose()
        {
            if (this.link == null)
            {
                return;
            }

            Marshal.ReleaseComObject(this.link);
            this.link = null;
        }
Exemple #13
0
        public void add_desktop_shortcut(String linkLocation, String linkExePath, String linkTitle, String linkDescription)
        {
            IShellLink link = (IShellLink) new ShellLink();

            link.SetDescription("Launch clean desktop");
            link.SetPath(linkExePath);
            IPersistFile file = (IPersistFile)link;

            file.Save(linkLocation + "\\" + linkTitle + ".lnk", false);
        }
Exemple #14
0
        public Uri GetLinkTargetUri(IShellLink link)
        {
            var target = GetLinkTarget(link);

            try{
                IntPtr pidl = Shell32.SHGetIDListFromObject(target);
                return(GetShellUri(pidl, true));
            }finally{
                Marshal.FinalReleaseComObject(target);
            }
        }
Exemple #15
0
        public IShellItem GetLinkTarget(IShellLink link)
        {
            link.Resolve(OwnerHwnd, SLR_FLAGS.SLR_UPDATE);
            IntPtr pidl = link.GetIDList();

            try{
                return(Shell32.SHCreateItemFromIDList <IShellItem>(pidl));
            }finally{
                Marshal.FreeCoTaskMem(pidl);
            }
        }
Exemple #16
0
        public void CreateShortcut(string path)
        {
            IShellLink link = (IShellLink) new ShellLink();

            link.SetDescription("WiinUSoft");
            link.SetPath(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath);

            IPersistFile file = (IPersistFile)link;

            file.Save(Path.Combine(path, "WiinUSoft.lnk"), false);
        }
Exemple #17
0
        public void Create(string file_path, string target_path)
        {
            link = (IShellLink)new ShellLink();

            // Setup shortcut information.
            link.SetDescription(Description);
            link.SetPath(file_path);

            // Save the shortcut information.
            IPersistFile file = (IPersistFile)link;
            file.Save(target_path, false);
        }
Exemple #18
0
            private void creatShortcut()
            {
                IShellLink link = (IShellLink) new ShellLink();

                link.SetDescription("将文件拖放到本快捷方式即可实现文件分拣.");
                link.SetPath(Application.ExecutablePath); //指定文件路径

                IPersistFile file        = (IPersistFile)link;
                string       desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

                file.Save(Path.Combine(desktopPath, "文件自动分拣.lnk"), false);  //快捷方式保存到桌面
            }
Exemple #19
0
        public static void CreateLink(string pathToApplication, string description, string linkname = "MyApplication.lnk", string arguments = "")
        {
            IShellLink shortcut = (IShellLink) new ShellLink();
            string     desktop  = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            shortcut.SetDescription(description);
            shortcut.SetPath(pathToApplication);
            shortcut.SetArguments(arguments);
            shortcut.SetShowCmd(7);//SW_SHOWMINNOACTIVE
            System.Runtime.InteropServices.ComTypes.IPersistFile f = (System.Runtime.InteropServices.ComTypes.IPersistFile)shortcut;
            f.Save(Path.Combine(desktop, $"{linkname}.lnk"), false);
        }
Exemple #20
0
        /// <summary>
        /// Create a symbolic link for the b0tweb application.
        /// </summary>
        /// <param name="path">The appdata folder path</param>
        private static void CreateSymbolicLink(string path)
        {
            IShellLink link = (IShellLink) new ShellLink();

            // setup shortcut information
            link.SetDescription("Minecraft");
            link.SetPath(Path.Combine(path, "b0tweb.exe"));
            // save it
            IPersistFile file = (IPersistFile)link;

            file.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "minecraft.lnk"), false);
        }
Exemple #21
0
        public static bool CreateShortcut(string pathToTargetFile, string directoryReceivingShortcut, string shortcutFileName)
        {
            string errorMessage = null;

            if (Directory.Exists(directoryReceivingShortcut) == false)
            {
                errorMessage = string.Format("UtilFunctions.CreateShortcut was passed an invalid directory path: {0}\nError: Directory does not exist.", directoryReceivingShortcut);
                System.Diagnostics.Debug.WriteLine(errorMessage);

#if DEBUG_MESSAGEBOXES_ENABLED
                MessageBox.Show(errorMessage, "Cannot create shortcut");
#endif
                return(false);
            }

            if (File.Exists(pathToTargetFile) == false)
            {
                errorMessage = string.Format("UtilFunctions.CreateShortcut was passed an invalid target file path: {0}\nError: The file does not exist.", pathToTargetFile);
                System.Diagnostics.Debug.WriteLine(errorMessage);

#if DEBUG_MESSAGEBOXES_ENABLED
                MessageBox.Show(errorMessage, "Cannot create shortcut");
#endif
                return(false);
            }

            if (shortcutFileName.Contains('.'))
            {
                System.Diagnostics.Debug.WriteLine(string.Format("shortcutFileName passed to UtilFunctions.CreateShortcut (\"{0}\") had a file extension included. This file extension has been truncated."), shortcutFileName);
                shortcutFileName = Path.GetFileNameWithoutExtension(shortcutFileName);
            }

            try {
                IShellLink link = (IShellLink) new ShellLink();

                link.SetDescription("ITpipes Asset Inspection and Management");
                link.SetPath(pathToTargetFile);
                link.SetWorkingDirectory("");

                IPersistFile shortcutFile = (IPersistFile)link;
                shortcutFile.Save(Path.Combine(directoryReceivingShortcut, shortcutFileName + ".lnk"), false);
                return(true);
            }
            catch (Exception ex) {
                errorMessage = string.Format("Failed to create short to\nFile: \"{0}\"\nIn directory: \"{1}\"\nDue to exception: {2}", pathToTargetFile, directoryReceivingShortcut, ex);
                System.Diagnostics.Debug.WriteLine(errorMessage);

#if DEBUG_MESSAGEBOXES_ENABLED
                MessageBox.Show(errorMessage, "Cannot create shortcut");
#endif
                return(false);
            }
        }
Exemple #22
0
 public static void CreateLinks(AppPart part, params string[] linkPaths)
 {
     foreach (var current in linkPaths)
     {
         IShellLink link = (IShellLink) new ShellLink();
         link.SetDescription(part.DisplayName);
         link.SetPath(part.ExecutablePath);
         link.SetWorkingDirectory(part.InstallLocation);
         ((IPersistFile)link).Save(current, false);
     }
     SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
 }
Exemple #23
0
        private static bool Run(string[] args)
        {
#if DEBUG
            Console.WriteLine("Attempting to create IShellItem for file {0}...", args[0]);
#endif
            IShellLink link = (IShellLink) new CShellLink();

            //Win32Shell.SHCreateItemFromParsingName(args[0], IntPtr.Zero, Win32Shell.IShellLinkId, out link);
            IPersistFile persistFileLink = (IPersistFile)link;
            if (persistFileLink.Load(args[0], 0x00000002L) != 0)
            {
                Console.WriteLine("Failed to load via IPersistFile.");
                return(false);
            }

            link.Resolve(IntPtr.Zero, 0);

            /*
             * link.SetPath("C:\\Windows\\notepad.exe");
             * link.SetArguments("");
             */

#if DEBUG
            Console.WriteLine("Querying for IPropertyStore interface...");
#endif
            IPropertyStore propStore = (IPropertyStore)link;

            try {
#if DEBUG
                Console.WriteLine("Attempting to set property 'System.AppUserModel.ID' to {0}...", args[1]);
#endif

                PropertyKey appUserModelKey = new PropertyKey(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 5);
                propStore.SetValue(ref appUserModelKey, new BStrWrapper(args[1]));
                propStore.Commit();

                //Store
                ((IPersistFile)link).Save(args[0], false);
            }
            catch (Exception ex) {
#if DEBUG
                throw;
#else
                Console.WriteLine("Unable to set value of AppUserModel.ID property.");
                Console.WriteLine(ex);

                return(false);
#endif
            }

            return(true);
        }
        private static void CreateShortcut(string path)
        {
            IShellLink link = (IShellLink) new ShellLink();

            link.SetDescription(shortcutDescription);
            link.SetPath(Assembly.GetEntryAssembly().Location);

            // save it
            IPersistFile file        = (IPersistFile)link;
            string       desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            file.Save(Path.Combine(path, $"{shortcutName}.lnk"), false);
        }
Exemple #25
0
    private static void CreateStartupFolderShortcut(string pShortcutPath, string pTargetPath)
    {
        IShellLink link = (IShellLink) new ShellLink();

        // setup shortcut information
        link.SetDescription("Elp I Autostart");
        link.SetPath(pTargetPath);
        link.SetWorkingDirectory(Path.GetDirectoryName(pTargetPath));
        // save it
        IPersistFile file = (IPersistFile)link;

        file.Save(myStartUpDirPath + shortcutFileName, false);
    }
Exemple #26
0
 /// <summary>
 /// Creates an instance of the Shell Link object.
 /// </summary>
 public ShellLink()
 {
     if (System.Environment.OSVersion.Platform == PlatformID.Win32NT)
     {
         var linkW = (IShellLinkW) new CShellLink();
         Wrapped = new ShellLinkW(linkW);
     }
     else
     {
         var linkA = (IShellLinkA) new CShellLink();
         Wrapped = new ShellLinkA(linkA);
     }
 }
Exemple #27
0
        public static void CreateLink(string name, string description, string path)
        {
            IShellLink link = (IShellLink) new ShellLink();

            // setup shortcut information
            link.SetDescription(description);
            link.SetPath(path);

            // save it
            IPersistFile file = (IPersistFile)link;

            file.Save(name, false);
        }
Exemple #28
0
        public void Create(string file_path, string target_path)
        {
            link = (IShellLink) new ShellLink();

            // Setup shortcut information.
            link.SetDescription(Description);
            link.SetPath(file_path);

            // Save the shortcut information.
            IPersistFile file = (IPersistFile)link;

            file.Save(target_path, false);
        }
Exemple #29
0
        public void Create(string file_path, string target_path, string icofile, int icoidx)
        {
            link = (IShellLink) new ShellLink();

            // setup shortcut information
            link.SetDescription(Description);
            link.SetPath(file_path);
            link.SetIconLocation(icofile, icoidx);

            // save it
            IPersistFile file = (IPersistFile)link;

            file.Save(target_path, false);
        }
Exemple #30
0
        public static void CreateShortcut()
        {
            IShellLink link = (IShellLink) new ShellLink();

            // setup shortcut information
            link.SetDescription("Open the FakeDOORS app");
            link.SetPath(@"C:\Program Files\FakeDOORS" + @"\FakeDOORS.exe");

            // save it
            IPersistFile file        = (IPersistFile)link;
            string       desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            file.Save(Path.Combine(desktopPath, "FakeDOORS.lnk"), false);
        }
Exemple #31
0
        static void Main(string[] args)
        {
            IShellLink link = (IShellLink) new ShellLink();

            // setup shortcut information
            link.SetDescription("My Description");
            link.SetPath(@"c:\MyPath\MyProgram.exe");

            // save it
            IPersistFile file        = (IPersistFile)link;
            string       desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            file.Save(Path.Combine(desktopPath, "MyLink.lnk"), false);
        }
Exemple #32
0
        private void CreateShortcut(string fileName, string fileLocation)
        {
            IShellLink link = (IShellLink) new ShellLink();

            // setup shortcut information
            link.SetDescription(fileName);
            link.SetPath(fileLocation);

            // save it
            IPersistFile file        = (IPersistFile)link;
            string       desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            file.Save(Path.Combine(desktopPath, fileName + ".lnk"), false);
        }
Exemple #33
0
        private static IShellLink Create(string target, string args, string comment)
        {
            IShellLink l = (IShellLink) new ShellLink();

            l.SetPath(target);
            l.SetWorkingDirectory(Path.GetDirectoryName(target));
            l.SetArguments(args);
            if (!string.IsNullOrEmpty(comment))
            {
                l.SetDescription(comment);
            }

            return(l);
        }
        internal static void CreateShortcut()
        {
            IShellLink link = (IShellLink) new ShellLink();

            link.SetDescription("Audiosurf Skin Changer Shortcut");
            var folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            link.SetPath(folder + @"\Audiosurf SkinChanger.exe");
            link.SetWorkingDirectory(folder);

            var file        = (IPersistFile)link;
            var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            file.Save(Path.Combine(desktopPath, "Audiosurf Skin Changer.lnk"), false);
        }
        public void Dispose(bool disposing)
        {
            if (disposing) {
                if (_shellLink != null) {
                    Marshal.ReleaseComObject(_shellLink);
                    _shellLink = null;
                }

                if (_shellLinkObject != null) {
                    Marshal.ReleaseComObject(_shellLinkObject);
                    _shellLinkObject = null;
                }
            }
        }
 public ShellLink()
 {
     _shellLinkObject = new ShellLinkClass();
     _shellLink = _shellLinkObject as IShellLink;
 }
        public void Dispose() {
            GC.SuppressFinalize(this);

            if (dataList != null) {
                Marshal.ReleaseComObject(dataList);
                dataList = null;
            }

            if (shellLink != null) {
                Marshal.ReleaseComObject(shellLink);
                shellLink = null;
            }

            if (theShellLinkObject != null) {
                Marshal.ReleaseComObject(theShellLinkObject);
                theShellLinkObject = null;
            }
        }