Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Name "COM Test"
- OutFile "COM Test.exe"
- Caption "NSIS $(^Name)"
- RequestExecutionLevel user
- XPStyle On
- /* Use specific AMUI or let windows auto detect?
- */!define MyAppUserModelId "Nullsoft.NSIS.Example.COM-Test" ;*/
- ;!define ForceAddRecentAUMI
- !define ShortcutName "NSIS COM Test.lnk"
- !define MyExt ".nsi"
- !define MyProgId "NSIS.COM-Test${MyExt}"
- !include LogicLib.nsh
- !include nsDialogs.nsh
- !include WinCore.nsh
- !include Win\COM.nsh
- !include Win\Propkey.nsh
- !include WinVer.nsh
- !define /ifndef SHCNE_ASSOCCHANGED 0x08000000
- !define /ifndef SHARD_PATHW 0x00000003
- !define /ifndef SHARD_APPIDINFOIDLIST 0x00000005
- Section
- SectionEnd
- Page custom PageCreate
- Function .onInit
- !ifdef MyAppUserModelId
- System::Call 'SHELL32::SetCurrentProcessExplicitAppUserModelID(w "${MyAppUserModelId}")i'
- !endif
- ${IfNot} ${AtLeastWinVista}
- ;IStartMenuPinnedList is documented as Vista+
- MessageBox mb_iconexclamation "This example is only useful on Vista+"
- ${EndIf}
- FunctionEnd
- Function PageCreate
- GetDlgItem $0 $hwndparent 2
- ShowWindow $0 0 ;Hide cancel button
- nsDialogs::Create 1018
- Pop $0
- ${NSD_CreateButton} 0 0 49% 13u "Create Startmenu shortcut"
- Pop $0
- ${NSD_OnClick} $0 CreateLnk
- ${NSD_CreateButton} 51% 0 49% 13u "Delete Startmenu shortcut"
- Pop $0
- ${NSD_OnClick} $0 DeleteLnk
- ${NSD_CreateButton} 0 15u 100% 13u "Register file type (${MyExt})"
- Pop $0
- ${NSD_OnClick} $0 FTReg
- ${NSD_CreateButton} 0 30u 100% 13u "Create dummy recent item"
- Pop $0
- ${NSD_OnClick} $0 CreateDummyRecent
- ${NSD_CreateButton} 0 45u 100% 13u "Unregister file type (${MyExt})"
- Pop $0
- ${NSD_OnClick} $0 FTUnReg
- nsDialogs::Show
- FunctionEnd
- !macro RegSafeDeleteEmptyKey HKEY Path
- Push $1
- Push $0
- StrCpy $0 "${Path}"
- ReadRegStr $1 ${HKEY} $0 ""
- ${IfThen} $1 == "" ${|} EnumRegValue $1 ${HKEY} $0 0 ${|}
- ${IfThen} $1 == "" ${|} DeleteRegKey /IfEmpty ${HKEY} $0 ${|}
- Pop $0
- Pop $1
- !macroend
- Function FTUnReg
- Pop $0
- DeleteRegValue HKCU "Software\Classes\${MyExt}\OpenWithProgIds" "${MyProgId}"
- DeleteRegKey HKCU "Software\Classes\${MyProgId}"
- !insertmacro RegSafeDeleteEmptyKey HKCU "Software\Classes\${MyExt}\OpenWithProgIds"
- !insertmacro RegSafeDeleteEmptyKey HKCU "Software\Classes\${MyExt}"
- System::Call 'SHELL32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED},i,p,p)'
- FunctionEnd
- Function FTReg
- Pop $0
- WriteRegBin HKCU "Software\Classes\${MyExt}\OpenWithProgIds" "${MyProgId}" ""
- !ifdef MyAppUserModelId
- WriteRegStr HKCU "Software\Classes\${MyProgId}" "AppUserModelId" "${MyAppUserModelId}"
- !endif
- ;Override icon? WriteRegStr HKCU "Software\Classes\${MyProgId}\DefaultIcon" "" '"$exepath"'
- WriteRegStr HKCU "Software\Classes\${MyProgId}\shell\open\command" "" '"$exepath" "%1"'
- System::Call 'SHELL32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED},i,p,p)'
- FunctionEnd
- Function CreateDummyRecent
- Pop $9
- EnableWindow $9 0
- ReadRegDWORD $2 HKCU "Software\Classes\${MyProgId}" "NSIS-DummyCount"
- IntOp $2 $2 + 1
- WriteRegDWORD HKCU "Software\Classes\${MyProgId}" "NSIS-DummyCount" $2
- StrCpy $1 "$desktop\NSIS COM Test $2${MyExt}"
- FileOpen $0 "$1" a
- FileClose $0
- !ifdef MyAppUserModelId & ForceAddRecentAUMI
- System::Call 'SHELL32::ILCreateFromPath(w "$1")p.r2'
- ${If} $2 <> 0
- System::Call '*(p $2,p,&w129 "${MyAppUserModelId}")p.r3' ;SHARDAPPIDINFOIDLIST+(WCHAR*)AppUserModelId
- ${If} $3 <> 0
- IntOp $4 ${__WIN_PTRSIZE} * 2
- IntOp $4 $3 + $4
- System::Call '*$3(p,p $4)'
- System::Call 'SHELL32::SHAddToRecentDocs(i ${SHARD_APPIDINFOIDLIST},p $3)'
- System::Free $3
- ${EndIf}
- System::Call 'SHELL32::ILFree(pr2)'
- ${EndIf}
- !else
- System::Call 'SHELL32::SHAddToRecentDocs(i ${SHARD_PATHW},w "$1")'
- !endif
- Sleep 1500
- Delete $1
- EnableWindow $9 1
- FunctionEnd
- !macro CreatePropVariantStrW str sysvaroutProp
- System::Call 'SHLWAPI::SHStrDup(t "${str}",*p.s)' ; TODO: Should really be error checking here!
- System::Call *${SYSSTRUCT_PROPVARIANT}(${VT_LPWSTR},,s)p.${sysvaroutProp}
- !macroend
- Function CreateLnk
- Pop $0
- CreateShortcut "$SMPrograms\${ShortcutName}" '"$EXEPATH"'
- !ifdef MyAppUserModelId
- ;Set the AppUserModelId on our .lnk (We have no tasks to show in the jump list, but this is just a sample)
- !insertmacro ComHlpr_CreateInProcInstance ${CLSID_ShellLink} ${IID_IShellLink} r1 .r0
- ${If} $1 <> 0
- ${IUnknown::QueryInterface} $1 '("${IID_IPersistFile}",.r2)'
- ${If} $2 <> 0
- ${IPersistFile::Load} $2 '("$SMPrograms\${ShortcutName}",${STGM_READWRITE}).r0'
- ${If} $0 = 0
- ${IUnknown::QueryInterface} $1 '("${IID_IPropertyStore}",.r3).r0'
- ${If} $3 <> 0
- System::Call '*${SYSSTRUCT_PROPERTYKEY}(${PKEY_AppUserModel_ID})p.r4'
- ${If} $4 <> 0
- !insertmacro CreatePropVariantStrW "${MyAppUserModelId}" r5
- ${If} $5 <> 0
- ${IPropertyStore::SetValue} $3 (r4,r5)i.r0
- System::Call 'OLE32::PropVariantClear(pr5)'
- System::Free $5
- ${If} $0 = 0
- ${IPropertyStore::Commit} $3 ()i.r0
- ${If} $0 = 0
- ${IPersistFile::Save} $2 '(p 0,1)i.r0' ;First parameter is w by default, we need to pass NULL!
- ${EndIf}
- ${EndIf}
- ${EndIf}
- System::Free $4
- ${EndIf}
- ${IUnknown::Release} $3 ""
- ${EndIf}
- ${EndIf}
- ${IUnknown::Release} $2 ""
- ${EndIf}
- ${IUnknown::Release} $1 ""
- ${EndIf}
- !else
- StrCpy $0 0
- !endif
- MessageBox mb_ok 'You can now pin the shortcut to the startmenu and taskbar...$\nHRESULT=$0'
- FunctionEnd
- Function DeleteLnk
- Pop $0
- !insertmacro ComHlpr_CreateInProcInstance ${CLSID_StartMenuPin} ${IID_IStartMenuPinnedList} r2 .r0
- ${If} $2 <> 0
- System::Call 'SHELL32::SHCreateItemFromParsingName(w "$SMPrograms\${ShortcutName}",p0,g "${IID_IShellItem}",*p.r1)i.r0'
- ${If} $1 <> 0
- ${IStartMenuPinnedList::RemoveFromList} $2 ($1).r0
- ${IUnknown::Release} $1 ""
- ${EndIf}
- ${IUnknown::Release} $2 ""
- ${EndIf}
- Delete "$SMPrograms\${ShortcutName}"
- Messagebox mb_ok 'IStartMenuPinnedList::RemoveFromList: HRESULT=$0'
- FunctionEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement