/// <summary> /// Create an empty shell link object /// </summary> public ShellLink() { theShellLinkObject = new ShellLinkCoClass(); shellLink = (IShellLink)theShellLinkObject; dataList = (IShellLinkDataList)theShellLinkObject; consoleProperties = new ConsoleProperties(this); }
/// <summary> /// Create an empty shell link object /// </summary> public ShellLink() { theShellLinkObject = new ShellLinkCoClass(); shellLink = (IShellLink) theShellLinkObject; dataList = (IShellLinkDataList) theShellLinkObject; consoleProperties = new ConsoleProperties(this); }
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; } }
/// <summary> /// Creates a shortcut to enable the app to receive toast notifications. /// </summary> /// <remarks> /// Documentation: https://docs.microsoft.com/en-us/windows/win32/shell/enable-desktop-toast-with-appusermodelid /// </remarks> /// <param name="shortcutPath">Full path to the shortcut (including .lnk), must be in Program Files or Start Menu</param> /// <param name="appExecutablePath">Path the to app that receives notifications</param> /// <param name="arguments">Optional arguments</param> /// <param name="appName">The name of the app - used to create the toast</param> /// <param name="activatorId">The activation id</param> public static void RegisterAppForNotifications(string shortcutPath, string appExecutablePath, string arguments, string appName, string activatorId) { var shellLinkClass = new ShellLinkCoClass(); IShellLinkW shellLink = (IShellLinkW)shellLinkClass; shellLink.SetPath(appExecutablePath); IPropertyStore propertyStore = (IPropertyStore)shellLinkClass; IPersistFile persistFile = (IPersistFile)shellLinkClass; if (arguments != null) { shellLink.SetArguments(arguments); } // https://docs.microsoft.com/en-us/windows/win32/properties/props-system-appusermodel-id propertyStore.SetValue(new PropertyKey("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3", 5), new PROPVARIANT(appName)); // https://docs.microsoft.com/en-us/windows/win32/properties/props-system-appusermodel-toastactivatorclsid propertyStore.SetValue(new PropertyKey("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3", 26), new PROPVARIANT(new Guid(activatorId))); propertyStore.Commit(); persistFile.Save(shortcutPath, true); }
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; } }