コード例 #1
0
ファイル: ShellLink.cs プロジェクト: jsydenstricker/oneget
        public virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_shellLink != null)
                {
                    Marshal.ReleaseComObject(_shellLink);
                    _shellLink = null;
                }

                if (_shellLinkObject != null)
                {
                    Marshal.ReleaseComObject(_shellLinkObject);
                    _shellLinkObject = null;
                }
            }
        }
コード例 #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
コード例 #3
0
 public ShellLink()
 {
     _shellLinkObject = new ShellLinkClass();
     _shellLink = _shellLinkObject as IShellLink;
 }
コード例 #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;
                }
            }
        }
コード例 #5
0
ファイル: ShellLink.cs プロジェクト: jsydenstricker/oneget
 public ShellLink()
 {
     _shellLinkObject = new ShellLinkClass();
     _shellLink       = _shellLinkObject as IShellLink;
 }