Exemplo n.º 1
0
        public virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_shellLink != null)
                {
                    Marshal.ReleaseComObject(_shellLink);
                    _shellLink = null;
                }

                if (_shellLinkObject != null)
                {
                    Marshal.ReleaseComObject(_shellLinkObject);
                    _shellLinkObject = null;
                }
            }
        }
Exemplo n.º 2
0
        public string CreateShortcut(string shortcutPath)
        {
            UnsafeNativeMethods.IShellLinkW  shortcut;
            UnsafeNativeMethods.IPersistFile shortcutFile;

            if (string.IsNullOrEmpty(shortcutPath))
            {
                throw new ArgumentNullException();
            }
            if (string.IsNullOrEmpty(TargetPath))
            {
                throw new ArgumentNullException();
            }

            shortcut     = null;
            shortcutFile = null;
            try
            {
                if (!IsFolderShortcut)
                {
                    shortcut = new ShellLinkClass() as UnsafeNativeMethods.IShellLinkW;
                }
                else
                {
                    shortcut = new FolderShortcutClass() as UnsafeNativeMethods.IShellLinkW;
                } // if-else

                shortcut.SetPath(TargetPath);
                if (!string.IsNullOrEmpty(Arguments))
                {
                    shortcut.SetArguments(Arguments);
                }
                if (!string.IsNullOrEmpty(Description))
                {
                    shortcut.SetDescription(Description);
                }
                if (!string.IsNullOrEmpty(WorkingDirectory))
                {
                    shortcut.SetWorkingDirectory(WorkingDirectory);
                }
                if (!string.IsNullOrEmpty(IconLocation))
                {
                    shortcut.SetIconLocation(IconLocation, IconIndex);
                }

                shortcutFile = shortcut as UnsafeNativeMethods.IPersistFile;
                if (!shortcutPath.EndsWith(".lnk"))
                {
                    shortcutPath += ".lnk";
                }
                shortcutPath = System.IO.Path.GetFullPath(shortcutPath);
                shortcutFile.Save(shortcutPath, true);

                return(shortcutPath);
            }
            finally
            {
                if (shortcutFile != null)
                {
                    Marshal.ReleaseComObject(shortcutFile);
                }
                if (shortcut != null)
                {
                    Marshal.ReleaseComObject(shortcut);
                }
            } // try-finally
        }     // Create
Exemplo n.º 3
0
 public ShellLink()
 {
     _shellLinkObject = new ShellLinkClass();
     _shellLink = _shellLinkObject as IShellLink;
 }
Exemplo n.º 4
0
        public void Dispose(bool disposing)
        {
            if (disposing) {
                if (_shellLink != null) {
                    Marshal.ReleaseComObject(_shellLink);
                    _shellLink = null;
                }

                if (_shellLinkObject != null) {
                    Marshal.ReleaseComObject(_shellLinkObject);
                    _shellLinkObject = null;
                }
            }
        }
Exemplo n.º 5
0
 public ShellLink()
 {
     _shellLinkObject = new ShellLinkClass();
     _shellLink       = _shellLinkObject as IShellLink;
 }