public void Create (string file_path, string target_path) { link = (IShellLinkW) new CShellLink (); this.link.SetShowCmd (1); this.link.SetPath (target_path); (this.link as IPersistFile).Save (file_path, true); }
public void Dispose () { if (this.link == null ) return; Marshal.ReleaseComObject (this.link); this.link = null; }
/// <summary> /// Creates an instance of the Shell Link object. /// </summary> public ShellLink() { if (System.Environment.OSVersion.Platform == PlatformID.Win32NT) { linkW = (IShellLinkW)new CShellLink(); } else { linkA = (IShellLinkA)new CShellLink(); } }
// // IDisplosable implementation // public void Dispose() { if (m_Link != null) { Marshal.ReleaseComObject(m_Link); m_Link = null; } }
/// <summary> /// Creates an instance of the Shell Link object. /// </summary> public ShellLink() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { linkW = (IShellLinkW) new CShellLink(); } else { linkA = (IShellLinkA) new CShellLink(); } }
/// <summary> /// Creates an instance of the Shell Link object. /// </summary> public WindowsShortcut() { if (System.Environment.OSVersion.Platform == PlatformID.Win32NT) { linkW = (IShellLinkW) new CShellLink(); } else { linkA = (IShellLinkA) new CShellLink(); } }
/// <summary> /// Creates an instance of the Shell Link object. /// </summary> public ShellLink() { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { linkW = (IShellLinkW) new CShellLink(); } else { linkA = (IShellLinkA) new CShellLink(); } }
internal ShellLink() { if (System.Environment.OSVersion.Platform == PlatformID.Win32NT) { linkW = (IShellLinkW) new CShellLink(); } else { linkA = (IShellLinkA) new CShellLink(); } }
/// <summary> /// Release the native and managed objects /// </summary> /// <param name="disposing">Indicates that this is being called from Dispose(), rather than the finalizer.</param> protected virtual void Dispose(bool disposing) { if (nativePropertyStore != null) { Marshal.ReleaseComObject(nativePropertyStore); nativePropertyStore = null; } if (nativeShellLink != null) { Marshal.ReleaseComObject(nativeShellLink); nativeShellLink = null; } }
private static IntPtr FilePathToIDL(IShellLinkW shellLink, string filePath) { IntPtr idl; Marshal.ThrowExceptionForHR( shellLink.SetPath(filePath) ); Marshal.ThrowExceptionForHR( shellLink.GetIDList(out idl) ); return(idl); }
public ShellLink() { this.shortcutFile = ""; if (Environment.OSVersion.Platform == PlatformID.Win32NT) { this.linkW = (IShellLinkW) new CShellLink(); } else { this.linkA = (IShellLinkA) new CShellLink(); } }
/// /// <param name='linkPath'> /// Path to new or existing shortcut file (.lnk). /// </param> /// public ShellShortcut(string linkPath) { IPersistFile pf; m_sPath = linkPath; m_Link = (IShellLinkW) new ShellLink(); if (File.Exists(linkPath)) { pf = (IPersistFile) m_Link; pf.Load(linkPath, 0); } }
public void OpenAndSelect(string path) { IShellLinkW psl = Marshal.GetObjectForIUnknown(ppsl) as IShellLinkW; psl.SetPath(path); IntPtr pidl = IntPtr.Zero; psl.GetIDList(out pidl); SHOpenFolderAndSelectItems(pidl, 0, null, 0); Marshal.FreeCoTaskMem(pidl); Marshal.Release(ppsl); }
/// <summary> /// Dispose the object, releasing the COM Shortcut object /// </summary> public void Dispose() { if (linkW != null) { Marshal.ReleaseComObject(linkW); linkW = null; } if (linkA != null) { Marshal.ReleaseComObject(linkA); linkA = null; } }
static void InstallShortcut(string exePath, string shortcutPath, string applicationId, string iconPath, Type activatorType) { IShellLinkW newShortcut = (IShellLinkW) new CShellLink(); SetExePath(exePath, newShortcut); SetArguments(newShortcut); SetIconLocation(iconPath, newShortcut); IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut; SetAppId(applicationId, newShortcutProperties); SetActivatorId(activatorType, newShortcutProperties); SaveShortcut(shortcutPath, newShortcut); }
/// <summary> /// 初始化後載入捷徑檔案 /// </summary> /// <param name="FullLinkFileName">完整的捷徑檔案名稱</param> public ShellLink(string FullLinkFileName) { try { shellLinkW = (IShellLinkW) new CShellLink(); } catch { throw new COMException("Failed to create ShellLink object."); } if (FullLinkFileName != null) { Load(FullLinkFileName); } }
public void Release() { if (ppf != null) { Marshal.FinalReleaseComObject(ppf); ppf = null; } if (psl != null) { Marshal.FinalReleaseComObject(psl); psl = null; } }
////////////////////////////////////////////////////////////////////////////////////////////////////////// // CONSTRUCTOR // ////////////////////////////////////////////////////////////////////////////////////////////////////////// public ShellLinkWrapper(string filePath) { try { shellLink = new ShellLink() as IShellLinkW; } catch (Exception) { throw new COMException("Failed to create shellLink object!"); } //Load shortcut LoadShortcut(filePath); }
/// <summary> /// Constructor with creating shell link object and loading shortcut file /// </summary> /// <param name="shortcutPath">Shortcut file path</param> public ShellLink(string shortcutPath) { try { shellLink = (IShellLinkW)new CShellLink(); } catch (Exception ex) { throw new COMException("Failed to create Shell link object.", ex); } if (shortcutPath != null) // To avoid default constructor this.Load(shortcutPath); }
/// <summary> /// Dispose the object, releasing the COM ShellLink object /// </summary> public void Dispose() { if (linkW != null) { Marshal.ReleaseComObject(linkW); linkW = null; } if (linkA != null) { Marshal.ReleaseComObject(linkA); linkA = null; } GC.SuppressFinalize(this); }
public ShellLink(string lnkPath) { this.lnkPath = lnkPath; if (Unicode) { _slW = (IShellLinkW)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID_ShellLink))); ((IPersistFile)(_slW)).Load(lnkPath, 0); } else { _slA = (IShellLinkA)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID_ShellLink))); ((IPersistFile)(_slA)).Load(lnkPath, 0); } }
public void create(string shortcutPath = "") { if (!string.IsNullOrEmpty(shortcutPath)) { if (!shortcutPath.Contains("\\")) { this.ShortcutPath = this.generateLinkPath(shortcutPath); } else { this.ShortcutPath = shortcutPath; } } if (string.IsNullOrEmpty(this.ShortcutPath)) { this.ShortcutPath = this.generateDefaultLinkPath(); } string folderPath = Path.GetDirectoryName(this.ShortcutPath); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } // Find the path to the current executable IShellLinkW newShortcut = (IShellLinkW) new CShellLink(); // Create a shortcut to the exe ResultChecker.VerifyAndThrow("SetPath", newShortcut.SetPath(this.ExePath)); ResultChecker.VerifyAndThrow("SetArguments", newShortcut.SetArguments(this.Arguments)); // Open the shortcut property store, set the AppUserModelId property IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut; if (!string.IsNullOrEmpty(this.AppUserModelID)) { using (PropVariant appId = new PropVariant(this.AppUserModelID)) { ResultChecker.VerifyAndThrow("SetValue", newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, appId)); ResultChecker.VerifyAndThrow("Commit", newShortcutProperties.Commit()); } } // Commit the shortcut to disk IPersistFile newShortcutSave = (IPersistFile)newShortcut; ResultChecker.VerifyAndThrow("Save", newShortcutSave.Save(this.ShortcutPath, true)); }
/// /// <param name='linkPath'> /// Path to new or existing shortcut file (.lnk). /// </param> /// public ShellShortcut(string linkPath) { IPersistFile pf; m_sPath = linkPath; m_Link = (IShellLinkW) new ShellLink(); if (File.Exists(linkPath)) { File.Delete(linkPath); /*IPersistFile pf = (IPersistFile)m_Link; * pf.Load(linkPath, 0);*/ } }
/// <summary> /// Constructor with creating shell link object and loading shortcut file /// </summary> /// <param name="shortcutPath">Shortcut file path</param> public ShellLink(string shortcutPath) { try { shellLink = (IShellLinkW) new CShellLink(); } catch (Exception ex) { throw new COMException("Failed to create Shell link object.", ex); } if (shortcutPath != null) // To avoid default constructor { this.Load(shortcutPath); } }
public KfSymlink(LinkType shortcutlinkType) { dataBuffer = new StringBuilder(260); // Get a pointer to the IShellLink interface. switch (shortcutlinkType) { case LinkType.File: psl = (IShellLinkW)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(ClsidShellLink)), true); break; case LinkType.Folder: psl = (IShellLinkW)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(ClsidFolderShortcut)), true); break; } }
/*public void Dispose() * { * if (_linkW != null ) * { * Marshal.ReleaseComObject(_linkW); * _linkW = null; * } * if (_linkA != null) * { * Marshal.ReleaseComObject(_linkA); * _linkA = null; * } * }*/ protected virtual void Dispose(bool disposing) { if (disposing) { } if (_linkW != null) { Marshal.ReleaseComObject(_linkW); _linkW = null; } if (_linkA != null) { Marshal.ReleaseComObject(_linkA); _linkA = null; } }
private static JumpItem GetJumpItemForShellObject(object shellObject) { IShellItem2 shellItem = shellObject as IShellItem2; IShellLinkW shellLinkW = shellObject as IShellLinkW; if (shellItem != null) { return(new JumpPath { Path = shellItem.GetDisplayName((SIGDN)2147647488u) }); } if (shellLinkW != null) { StringBuilder stringBuilder = new StringBuilder(260); shellLinkW.GetPath(stringBuilder, stringBuilder.Capacity, null, SLGP.RAWPATH); StringBuilder stringBuilder2 = new StringBuilder(1024); shellLinkW.GetArguments(stringBuilder2, stringBuilder2.Capacity); StringBuilder stringBuilder3 = new StringBuilder(1024); shellLinkW.GetDescription(stringBuilder3, stringBuilder3.Capacity); StringBuilder stringBuilder4 = new StringBuilder(260); int iconResourceIndex; shellLinkW.GetIconLocation(stringBuilder4, stringBuilder4.Capacity, out iconResourceIndex); StringBuilder stringBuilder5 = new StringBuilder(260); shellLinkW.GetWorkingDirectory(stringBuilder5, stringBuilder5.Capacity); JumpTask jumpTask = new JumpTask { ApplicationPath = stringBuilder.ToString(), Arguments = stringBuilder2.ToString(), Description = stringBuilder3.ToString(), IconResourceIndex = iconResourceIndex, IconResourcePath = stringBuilder4.ToString(), WorkingDirectory = stringBuilder5.ToString() }; using (PROPVARIANT propvariant = new PROPVARIANT()) { IPropertyStore propertyStore = (IPropertyStore)shellLinkW; PKEY title = PKEY.Title; propertyStore.GetValue(ref title, propvariant); jumpTask.Title = (propvariant.GetValue() ?? ""); } return(jumpTask); } return(null); }
/// /// <param name='linkPath'> /// Path to new or existing shortcut file (.lnk). /// </param> /// public ShellShortcut(string linkPath) { IPersistFile pf; m_sPath = linkPath; #if UNICODE m_Link = (IShellLinkW) new ShellLink(); #else m_Link = (IShellLinkA) new ShellLink(); #endif if (File.Exists(linkPath)) { pf = (IPersistFile)m_Link; pf.Load(linkPath, 0); } }
/// <summary> /// Release the native and managed objects /// </summary> /// <param name="disposing">Indicates that this is being called from Dispose(), rather than the finalizer.</param> public void Dispose(bool disposing) { if (disposing) { title = null; } if (nativePropertyStore != null) { Marshal.ReleaseComObject(nativePropertyStore); nativePropertyStore = null; } if (nativeShellLink != null) { Marshal.ReleaseComObject(nativeShellLink); nativeShellLink = null; } }
private static string ShellLinkToString(IShellLinkW shellLink) { StringBuilder stringBuilder = new StringBuilder(260); shellLink.GetPath(stringBuilder, stringBuilder.Capacity, null, SLGP.RAWPATH); string text = null; using (PROPVARIANT propvariant = new PROPVARIANT()) { IPropertyStore propertyStore = (IPropertyStore)shellLink; PKEY title = PKEY.Title; propertyStore.GetValue(ref title, propvariant); text = (propvariant.GetValue() ?? ""); } StringBuilder stringBuilder2 = new StringBuilder(1024); shellLink.GetArguments(stringBuilder2, stringBuilder2.Capacity); return(stringBuilder.ToString().ToUpperInvariant() + text.ToUpperInvariant() + stringBuilder2.ToString()); }
public static ShellLinkEx Load(string strLnkFilePath) { try { CShellLink csl = new CShellLink(); IShellLinkW sl = (csl as IShellLinkW); if (sl == null) { Debug.Assert(false); return(null); } IPersistFile pf = (csl as IPersistFile); if (pf == null) { Debug.Assert(false); return(null); } pf.Load(strLnkFilePath, (int)(NativeMethods.STGM.Read | NativeMethods.STGM.ShareDenyWrite)); const int ccMaxPath = KeePassLib.Native.NativeMethods.MAX_PATH; const int ccInfoTip = NativeMethods.INFOTIPSIZE; ShellLinkEx r = new ShellLinkEx(); StringBuilder sb = new StringBuilder(ccMaxPath + 1); sl.GetPath(sb, sb.Capacity, IntPtr.Zero, 0); r.Path = sb.ToString(); sb = new StringBuilder(ccInfoTip + 1); sl.GetArguments(sb, sb.Capacity); r.Arguments = sb.ToString(); sb = new StringBuilder(ccInfoTip + 1); sl.GetDescription(sb, sb.Capacity); r.Description = sb.ToString(); return(r); } catch (Exception) { Debug.Assert(false); } return(null); }
private void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { if (_linkW != null) { Marshal.ReleaseComObject(_linkW); _linkW = null; } if (_linkA != null) { Marshal.ReleaseComObject(_linkA); _linkA = null; } } } }
public static void AddToRecentCategory(JumpTask jumpTask) { Verify.IsNotNull <JumpTask>(jumpTask, "jumpTask"); if (Utility.IsOSWindows7OrNewer) { IShellLinkW shellLinkW = JumpList.CreateLinkFromJumpTask(jumpTask, false); try { if (shellLinkW != null) { NativeMethods.SHAddToRecentDocs(shellLinkW); } } finally { Utility.SafeRelease <IShellLinkW>(ref shellLinkW); } } }
protected virtual void Dispose(Boolean disposing) { if (disposing) { // free managed resources } // free native resources if (linkW != null) { Marshal.ReleaseComObject(linkW); linkW = null; } if (linkA != null) { Marshal.ReleaseComObject(linkA); linkA = null; } }
private static void InstallShortcut(string shortcutPath, string APP_ID = "") { string _APP_ID = string.IsNullOrEmpty(APP_ID) ? pAPP_ID : APP_ID; string exePath = Process.GetCurrentProcess().MainModule.FileName; IShellLinkW newShortcut = (IShellLinkW) new CShellLink(); ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath)); ErrorHelper.VerifySucceeded(newShortcut.SetArguments("")); IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut; using (PropVariant appId = new PropVariant(_APP_ID + NotID)) { ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, appId)); ErrorHelper.VerifySucceeded(newShortcutProperties.Commit()); } IPersistFile newShortcutSave = (IPersistFile)newShortcut; ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true)); }
private static bool ListContainsShellObject(List <JumpList._ShellObjectPair> removedList, object shellObject) { if (removedList.Count == 0) { return(false); } IShellItem shellItem = shellObject as IShellItem; if (shellItem != null) { foreach (JumpList._ShellObjectPair current in removedList) { IShellItem shellItem2 = current.ShellObject as IShellItem; if (shellItem2 != null && shellItem.Compare(shellItem2, (SICHINT)805306368u) == 0) { bool result = true; return(result); } } return(false); } IShellLinkW shellLinkW = shellObject as IShellLinkW; if (shellLinkW != null) { foreach (JumpList._ShellObjectPair current2 in removedList) { IShellLinkW shellLinkW2 = current2.ShellObject as IShellLinkW; if (shellLinkW2 != null) { string a = JumpList.ShellLinkToString(shellLinkW2); string b = JumpList.ShellLinkToString(shellLinkW); if (a == b) { bool result = true; return(result); } } } return(false); } return(false); }
/// <summary> /// Generate a unique string for the ShellLink that can be used for equality checks. /// </summary> private static string ShellLinkToString(IShellLinkW shellLink) { var pathBuilder = new StringBuilder((int)Win32Value.MAX_PATH); shellLink.GetPath(pathBuilder, pathBuilder.Capacity, null, SLGP.RAWPATH); string title = null; // Need to use the property store to get the title for the link. using (PROPVARIANT pv = new PROPVARIANT()) { var propStore = (IPropertyStore)shellLink; PKEY pkeyTitle = PKEY.Title; propStore.GetValue(ref pkeyTitle, pv); // PKEY_Title should be an LPWSTR if it's not empty. title = pv.GetValue() ?? ""; } var argsBuilder = new StringBuilder((int)Win32Value.INFOTIPSIZE); shellLink.GetArguments(argsBuilder, argsBuilder.Capacity); // Path and title should be case insensitive. // Shell treats arguments as case sensitive because apps can handle those differently. return pathBuilder.ToString().ToUpperInvariant() + title.ToUpperInvariant() + argsBuilder.ToString(); }
/*public void Dispose() { if (_linkW != null ) { Marshal.ReleaseComObject(_linkW); _linkW = null; } if (_linkA != null) { Marshal.ReleaseComObject(_linkA); _linkA = null; } }*/ protected virtual void Dispose(bool disposing) { if (disposing) { } if (_linkW != null) { Marshal.ReleaseComObject(_linkW); _linkW = null; } if (_linkA != null) { Marshal.ReleaseComObject(_linkA); _linkA = null; } }
// The bulk of the clean-up code is implemented in Dispose(bool) protected virtual void Dispose(bool disposing) { // free native resources if there are any. if (link != null) { Marshal.ReleaseComObject(link); link = null; } }
public void Dispose() { if (this.PersistStream != null) { Marshal.FinalReleaseComObject(this.PersistStream); } this.LinkA = null; this.LinkW = null; this.PersistStream = null; }
public ShellLink(string linkFile) { try { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { shellLinkW = (IShellLinkW)new ShellLinkObject(); shellLinkA = null; } else { shellLinkA = (IShellLinkA)new ShellLinkObject(); shellLinkW = null; } } catch { throw new COMException("cannot create ShellLinkObject"); } if (linkFile != null) Load(linkFile); }
internal static void SHAddToRecentDocs(IShellLinkW shellLink) { SHAddToRecentDocs_ShellLink(SHARD.LINK, shellLink); }
/// <summary> /// <see cref="ShortcutClass"/> constructor /// </summary> /// <param name="linkPath">Path to existing shortcut file (.lnk).</param> public ShortcutClass(string linkPath) { try { Guid CLSID_ShellLink = new Guid("00021401-0000-0000-C000-000000000046"); Type shellLink = Type.GetTypeFromCLSID(CLSID_ShellLink); link = (IShellLinkW)(Activator.CreateInstance(shellLink)); if (File.Exists(linkPath)) { var pfile = (IPersistFile)link; pfile.Load(linkPath, 0); } } catch (COMException) { } }
public KfSymlink(LinkType shortcutlinkType) { dataBuffer = new StringBuilder(260); // Get a pointer to the IShellLink interface. switch (shortcutlinkType) { case LinkType.File: psl = (IShellLinkW) Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(ClsidShellLink)), true); break; case LinkType.Folder: psl = (IShellLinkW) Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(ClsidFolderShortcut)), true); break; } }
public ShellLink(string path) { this.shellLink = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("00021401-0000-0000-C000-000000000046"))) as IShellLinkW; if (File.Exists(path)) { IntPtr consoleProperties = IntPtr.Zero; ((IPersistFile)this.shellLink).Load(path, 0); try { ((IShellLinkDataList)this.shellLink).CopyDataBlock(0xA0000002, out consoleProperties); this.consoleProperties = (NT_CONSOLE_PROPS)Marshal.PtrToStructure(consoleProperties, typeof(NT_CONSOLE_PROPS)); } catch (Exception) { } } else { ((IPersistFile)this.shellLink).Save(path, true); } // Initialize default Console Properties (TODO: Fix this bug too) if (this.consoleProperties.dwSignature != 0xA0000002) { this.consoleProperties = new NT_CONSOLE_PROPS(); this.consoleProperties.cbSize = Marshal.SizeOf(this.consoleProperties); this.consoleProperties.dwSignature = 0xA0000002; this.consoleProperties.ColorTable = new uint[16]; for (int i = 0; i < 16; i++) { this.consoleProperties.ColorTable[i] = 0xffffffff; } } }
/// <summary> /// コンストラクタ /// </summary> /// <exception cref="COMException">IShellLinkインターフェイスを取得できませんでした。</exception> public ShellLinkUtility() { currentFile = ""; shellLinkW = null; shellLinkA = null; try { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { // Unicode環境 shellLinkW = (IShellLinkW)(new ShellLinkObject()); isUnicodeEnvironment = true; } else { // Ansi環境 shellLinkA = (IShellLinkA)(new ShellLinkObject()); isUnicodeEnvironment = false; } } catch { throw new COMException("IShellLinkインターフェイスを取得できませんでした。"); } }
protected virtual void Dispose(bool disposing) { if (shellLinkW != null) { // Release all references. Marshal.FinalReleaseComObject(shellLinkW); shellLinkW = null; } }
public ShellLink() { if (Environment.OSVersion.Platform == PlatformID.Win32NT) linkW = (IShellLinkW) new CShellLink(); else linkA = (IShellLinkA) new CShellLink(); }
// Construct with loading shortcut file. public ShellLink(string file) { try { shellLinkW = (IShellLinkW)new CShellLink(); } catch { throw new COMException("Failed to create ShellLink object."); } if (file != null) Load(file); }
private string RemoveCustomCategoryLink(IShellLinkW link) { string path = null; if (customCategoriesCollection != null) { StringBuilder sb = new StringBuilder(256); link.GetPath(sb, sb.Capacity, IntPtr.Zero, 2); path = sb.ToString(); // Remove this item from each category foreach (JumpListCustomCategory category in customCategoriesCollection) category.RemoveJumpListItem(path); } return path; }
private static extern void _SHAddToRecentDocs_ShellLink(SHARD uFlags, IShellLinkW pv);
public static void SHAddToRecentDocs(IShellLinkW shellLink) { _SHAddToRecentDocs_ShellLink(SHARD.LINK, shellLink); }
private void Initialize() { object obj2 = new CoShellLink(); this.LinkW = obj2 as IShellLinkW; if (this.LinkW == null) { this.LinkA = obj2 as IShellLinkA; if (this.LinkA == null) { throw new NotSupportedException("IShellLink"); } } this.PersistStream = obj2 as Microsoft.COM.IPersistStream; if (this.PersistStream == null) { throw new NotSupportedException("IPersistStream"); } }
/// <summary> /// Dispose the object, releasing the COM ShellLink object /// </summary> public void Dispose() { if (linkW != null ) { Marshal.ReleaseComObject(linkW); linkW = null; } if (linkA != null) { Marshal.ReleaseComObject(linkA); linkA = null; } }
public static extern void SHAddToRecentDocs(SHARD uFlags, IShellLinkW pv);