Anders
You wrote a plugin called WinShell (https://nsis.sourceforge.io/WinShell_plug-in). It is 32bit (Unicode) plugin.
It allows to create a shortcut that also sets the PKEY_AppUserModel_ID (https://learn.microsoft.com/en-us/wi...2/shell/appids).
I tested it in NSIS 32-bit and it works very well.
So, it is very helpful, but I would like to not use any plugin (I use NSIS 64). I want to create a shortcut with my installer using System plugin (a shorcut to my app that already set AppUserModelID, using SetCurrentProcessExplicitAppUserModelID() function).
Could you show how to do this with System plugin and Win\COM.nsh - like you showed uninstallation (if I understand it well)?
My goal is to create a shortcut to my app with AppUserModelID so user can pin this shortcut to taskbar (and then Jumplist is working).
Ps: I think there is an example in COM.nsh how to create a shortcut, at the top of file (or something similar), am I right?
-Pawel
Creating a shortcut with an AppUserModelID using the System plug-in
4 posts
Yes, the example code in COM.nsh is basically what you need (just set a single property). Call SysAllocString and set this as VT_BSTR,, p $yoursysstring and SysFreeString the string after setting the value.
Call the UnpinShortcut macro from Integration.nsh in your uninstaller.
Call the UnpinShortcut macro from Integration.nsh in your uninstaller.
@Anders,
Thanks for quick answer.
It helped me and I created working solution (even though you didn't provide a ready-made solution - would be much easier :P).
So, here is my code to create a shortcut with AppUserModelID
You wrote:
I'm afraid the icon won't unpin because Microsoft doesn't accept it (in recent Windows releases). Perhaps it will work in Windows 7.
Thanks,
-Pawel
Thanks for quick answer.
It helped me and I created working solution (even though you didn't provide a ready-made solution - would be much easier :P).
So, here is my code to create a shortcut with AppUserModelID
; You can add keyboard shortcut to your shortcut file
!define MY_HOTKEY 0x0358 ; CTRL + SHIFT + X
; How to build HotKey?
; In Windows API, a hotkey is stored as a 16-bit WORD.
; This WORD is divided into two distinct parts: the High-order byte (modifiers) and the Low-order byte (virtual key code).
; 1. The High-Order Byte (Modifiers)
; This byte defines which "special" keys need to be held down. You combine them by adding their values (bitwise OR).
; - SHIFT 0x01
; - CONTROL 0x02
; - ALT 0x04 EXT (Extended Key) 0x08
; Examples:
; CTRL + ALT: 0x02 + 0x04 = 0x06
; CTRL + SHIFT: 0x02 + 0x01 = 0x03
; 2. The Low-Order Byte (Virtual Key Code)
; This byte defines the actual key on the keyboard.
; A through Z: Use their ASCII values (0x41 for 'A' through 0x5A for 'Z')
; F1 through F12: Range from 0x70 (F1) to 0x7B (F12).
; Digits 0 through 9: Range from 0x30 to 0x39.
; 3. Assembly Examples
; To create the final hex value, you put the Modifier in front of the Key Code.
; Thanks, AI :P
!insertmacro ComHlpr_CreateInProcInstance ${CLSID_ShellLink} ${IID_IShellLink} r0 ""
${If} $0 P<> 0
; Set Program Path with Parameters
${IShellLink::SetPath} $0 '("$INSTDIR\MyApp.exe").r1' ; Program Path
${IShellLink::SetArguments} $0 '("/PARAM1 /PARAM2").r2' ; Program Parameters
; Set Icon Location (in case you want external icon)
${IShellLink::SetIconLocation} $0 '("$INSTDIR\IconPack.dll", 3).r3'
; Set Working Directory
${IShellLink::SetWorkingDirectory} $0 '("$INSTDIR").r4'
; Set Tooltip
${IShellLink::SetDescription} $0 '("Some description text for tooltip").r5'
; Set Window State
${IShellLink::SetShowCmd} $0 '(${SW_SHOWNORMAL}).r6'
; Set Keyboard Shortcut (see above)
${IShellLink::SetHotkey} $0 '(${MY_HOTKEY}).r7'
${If} $1 = 0
${AndIf} $2 = 0
; Set Property (AppUserModelID)
${IUnknown::QueryInterface} $0 '("${IID_IPropertyStore}",.r1)'
${If} $1 P<> 0
System::Call "oleaut32::SysAllocString(w 'CompanyName.ProductName.SubProduct.VersionInformation') p .r4" ; Program AppUserModelID (must be the same as your app defines!)
; -
System::Call '*${SYSSTRUCT_PROPERTYKEY}(${PKEY_AppUserModel_ID})p.r2'
System::Call '*${SYSSTRUCT_PROPVARIANT}(${VT_BSTR},, p r4)p.r3'
${IPropertyStore::SetValue} $1 '($2, $3)'
${IPropertyStore::Commit} $1 ""
; -
System::Call "oleaut32::SysFreeString(p r4)"
System::Free $2
System::Free $3
${IUnknown::Release} $1 ""
${EndIf}
; Save File
${IUnknown::QueryInterface} $0 '("${IID_IPersistFile}",.r1)'
${If} $1 P<> 0
${IPersistFile::Save} $1 '("$SMPROGRAMS\MyNewLink.lnk", 1)' ; Link File
${IUnknown::Release} $1 ""
${EndIf}
${EndIf} ; Path/Params
${IUnknown::Release} $0 ""
${EndIf} Hope, someone can use it...You wrote:
Call the UnpinShortcut macro from Integration.nsh in your uninstaller.I am sure You mean this code (from your WinShell plugin page):
!include "Win\COM.nsh"
!include LogicLib.nsh
Section Uninstall
!insertmacro ComHlpr_CreateInProcInstance ${CLSID_DestinationList} ${IID_ICustomDestinationList} r1 ""
${If} $1 P<> 0
${ICustomDestinationList:eleteList} $1 '("${MyApp_AppUserModelId}")'
${IUnknown::Release} $1 ""
${EndIf}
!insertmacro ComHlpr_CreateInProcInstance ${CLSID_ApplicationDestinations} ${IID_IApplicationDestinations} r1 ""
${If} $1 P<> 0
${IApplicationDestinations::SetAppID} $1 '("${MyApp_AppUserModelId}")i.r0'
${If} $0 >= 0
${IApplicationDestinations::RemoveAllDestinations} $1 ''
${EndIf}
${IUnknown::Release} $1 ""
${EndIf}
!include Integration.nsh
${UnpinShortcut} "$SMPrograms\MyApp.lnk" ; Will not work!
Delete "$SMPrograms\MyApp.lnk" ; OK
SectionEnd I'm afraid the icon won't unpin because Microsoft doesn't accept it (in recent Windows releases). Perhaps it will work in Windows 7.
Thanks,
-Pawel
I'm sick, stuck in bed, the best I could do was hints.
https://learn.microsoft.com/en-us/wi...menupinnedlist does not say anything about 10 or 11. I know the code worked on 7/8 when I first wrote it.
https://learn.microsoft.com/en-us/wi...menupinnedlist does not say anything about 10 or 11. I know the code worked on 7/8 when I first wrote it.