示例#1
0
        public static void InstallShortcut(string exePath, string appId, string desc, string wkDirec, string iconLocation, string saveLocation, string arguments)
        {
            // Use passed parameters as to construct the shortcut
            IShellLinkW newShortcut = (IShellLinkW) new CShellLink();

            newShortcut.SetPath(exePath);
            newShortcut.SetDescription(desc);
            newShortcut.SetWorkingDirectory(wkDirec);
            newShortcut.SetArguments(arguments);
            newShortcut.SetIconLocation(iconLocation, 0);


            // Set the classID of the shortcut that is created
            // Crucial to avoid program stacking
            IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

            PropVariantHelper varAppId = new PropVariantHelper();

            varAppId.SetValue(appId);
            newShortcutProperties.SetValue(PROPERTYKEY.AppUserModel_ID, varAppId.Propvariant);

            // Save the shortcut as per passed save location
            IPersistFile newShortcutSave = (IPersistFile)newShortcut;

            newShortcutSave.Save(saveLocation, true);
        }
示例#2
0
        /**
         * Adds a new shortcut for the specified executable and app id.
         */
        public static void InstallShortcut(string exePath, string appId, Guid handler)
        {
            // Start a new shortcut object for our new shortcut.
            IShellLinkW newShortcut = (IShellLinkW) new CShellLink();

            newShortcut.SetPath(exePath);

            // Set our classid and handler GUID for the shortcut.
            IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

            PropVariantHelper varAppId = new PropVariantHelper();

            varAppId.SetValue(appId);
            newShortcutProperties.SetValue(PROPERTYKEY.AppUserModel_ID, varAppId.Propvariant);

            PropVariantHelper varToastId = new PropVariantHelper();

            varToastId.VarType = VarEnum.VT_CLSID;
            varToastId.SetValue(handler);
            newShortcutProperties.SetValue(PROPERTYKEY.AppUserModel_ToastActivatorCLSID, varToastId.Propvariant);

            // Save the shortcut.
            IPersistFile newShortcutSave = (IPersistFile)newShortcut;

            newShortcutSave.Save(SHORTCUT_PATH, true);
        }
        /// <summary>
        /// Install shortcut.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="shortcutPath">The path of shortcut.</param>
        /// <param name="exePath">The path of program.</param>
        private static void InstallShortcut <T>(string shortcutPath, string exePath)
        {
            IShellLinkW newShortcut = (IShellLinkW) new CShellLink();

            // Create a shortcut to the exe
            newShortcut.SetPath(exePath);

            // Open the shortcut property store, set the AppUserModelId property
            IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

            PropVariantHelper varAppId = new PropVariantHelper();

            varAppId.SetValue(_aumid);
            newShortcutProperties.SetValue(PROPERTYKEY.AppUserModel_ID, varAppId.Propvariant);

            PropVariantHelper varToastId = new PropVariantHelper();

            varToastId.VarType = VarEnum.VT_CLSID;
            varToastId.SetValue(typeof(NotificationActivator).GUID);

            newShortcutProperties.SetValue(PROPERTYKEY.AppUserModel_ToastActivatorCLSID, varToastId.Propvariant);

            // Commit the shortcut to disk
            ShellHelpers.IPersistFile newShortcutSave = (ShellHelpers.IPersistFile)newShortcut;

            newShortcutSave.Save(shortcutPath, true);
        }
示例#4
0
        /// <summary>
        /// Borowed from https://github.com/WindowsNotifications/desktop-toasts
        /// THIS SAMPLE DOES NOT CLEAN CREATED SHORTCUT
        /// </summary>
        /// <param name="exePath"></param>
        private void RegisterShortcut(string exePath)
        {
            String shortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Windows\\Start Menu\\Programs\\My cool toast app.lnk";

            if (!File.Exists(shortcutPath))
            {
                IShellLinkW newShortcut = (IShellLinkW) new CShellLink();
                // Create a shortcut to the exe
                newShortcut.SetPath(exePath);

                // Open the shortcut property store, set the AppUserModelId property
                IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

                PropVariantHelper varAppId = new PropVariantHelper();

                varAppId.SetValue(myAppID);
                newShortcutProperties.SetValue(PROPERTYKEY.AppUserModel_ID, varAppId.Propvariant);

                // Commit the shortcut to disk
                IPersistFile newShortcutSave = (IPersistFile)newShortcut;
                newShortcutSave.Save(shortcutPath, true);
            }
        }