Adding your program to the Control Panel

From NSIS Wiki
Jump to navigationJump to search
Author: ZmAn3 (talk, contrib)


Description

These macros below add or remove items from the Control Panel. You have to refresh the Control Panel, if in use, in order to work. Tested only on Windows XP SP2.

How To Use

${WControlPanelItem_Add} `GUID` `Name` `Tip` `Exec` `Icon`
GUID
Your application GUID. If you don't have one, use the function from Create a GUID, a Globally Unique Identifier page.
Name
Name of the item to appear as the button name.
Exec
File to open when executing the item. It has to be an executable. Accepts parameters.
Icon
Specifies the icon to be used for the item.
${WControlPanelItem_Remove} `GUID`
GUID
Your application GUID used on ${WControlPanelItem_Add}.

The Macros

!define WControlPanelItem_Add `!insertmacro WControlPanelItem_Add`
!macro WControlPanelItem_Add `GUID` `Name` `Tip` `Exec` `Icon`
  WriteRegStr HKCR `CLSID\${GUID}` `` `${Name}`
  WriteRegStr HKCR `CLSID\${GUID}` `InfoTip` `${Tip}`
  WriteRegStr HKCR `CLSID\${GUID}\DefaultIcon` `` `${Icon}`
  WriteRegStr HKCR `CLSID\${GUID}\Shell\Open\Command` `` `${Exec}`
  WriteRegDWORD HKCR `CLSID\${GUID}\ShellFolder` `Attributes` `0`
  WriteRegStr HKLM `SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\${GUID}` `` `${Name}`
!macroend
 
!define WControlPanelItem_Remove `!insertmacro WControlPanelItem_Remove`
!macro WControlPanelItem_Remove `GUID`
  DeleteRegKey HKCR "CLSID\${GUID}"
  DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\${GUID}"
!macroend

Written by ZmAn3.
Modified by deguix.