Windows 7 Cascading Context Menu: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(removed unused regkey from second script, added x64 check (=important))
 
(10 intermediate revisions by one other user not shown)
Line 2: Line 2:
As of Windows 7, one can create cascading context menus through the registry.
As of Windows 7, one can create cascading context menus through the registry.


== Example Script ==
== Example Scripts ==
This example creates entries for the NSIS compiler for all file-types. It is yet uncertain if this can be limited to a single filetype only.
This example creates a cascaded context menu for the NSIS compiler, and if present also for the Unicode version of NSIS. The entries will be added to HKCR.
<highlight-nsis>Name "NSIS Window 7 Context Menu"
<highlight-nsis>Name "NSIS Window 7 Context Menu"
OutFile "nsW7Menu.exe"
OutFile "nsW7Menu.exe"
RequestExecutionLevel admin
InstallDir $PROGRAMFILES\NSIS
InstallDirRegKey HKLM Software\NSIS ""
; Pages
Page directory
Page instfiles
; Sections
Section ""
WriteRegStr HKCR ".nsi" "" "NSIS.Script"
;menu-name,submenu,icon
WriteRegStr HKCR \
"NSIS.Script\shell\NSIS.W7Menu" \
"MUIVerb" \
"NSIS"
WriteRegStr HKCR \
"NSIS.Script\shell\NSIS.W7Menu" \
"ExtendedSubCommandsKey" \
"NSIS.Script\W7Menu"
WriteRegStr HKCR \
"NSIS.Script\shell\NSIS.W7Menu" \
"Icon" \
"$INSTDIR\makensisw.exe,1"
;compile
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\compile" \
"MUIVerb" "Compile NSIS Script"
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\compile\command" \
"" \
'"$INSTDIR\makensisw.exe" "%1"'
;compile (choose compressor)
WriteRegStr HKCR  \
"NSIS.Script\W7Menu\shell\compile-compressor" \
"MUIVerb" \
"Compile NSIS Script (Choose Compressor)"
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\compile-compressor\command" \
"" \
'"$INSTDIR\makensisw.exe" /ChooseCompressor "%1"'
;repeat for Unicode NSIS
IfFileExists "$INSTDIR\Unicode\makensisw.exe" 0 End
;add separator above the next entry
WriteRegDWORD HKCR  \
"NSIS.Script\W7Menu\shell\ucompile"  \
"CommandFlags" \
"32"
;compile unicode
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\ucompile" \
"MUIVerb" \
"Compile Unicode NSIS Script"
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\ucompile\command" \
"" \
'"$INSTDIR\Unicode\makensisw.exe" "%1"'
;compile unicode (choose compressor)
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\ucompile-compressor" \
"MUIVerb" \
"Compile Unicode NSIS Script (Choose Compressor)"
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\ucompile-compressor\command" \
"" \
'"$INSTDIR\Unicode\makensisw.exe" /ChooseCompressor "%1"'
End:
SectionEnd</highlight-nsis>
This alternative version will add the keys to the CommandStore of HKLM instead.
<highlight-nsis>Name "NSIS Window 7 Context Menu"
OutFile "nsW7Menu-alt.exe"
RequestExecutionLevel admin
RequestExecutionLevel admin


InstallDir $PROGRAMFILES\NSIS
InstallDir $PROGRAMFILES\NSIS
InstallDirRegKey HKLM Software\NSIS ""
InstallDirRegKey HKLM Software\NSIS ""
;Includes
!include "x64.nsh"


; Pages
; Pages
Line 16: Line 95:


; Sections
; Sections
Section ""
Section ""
WriteRegStr HKCR ".nsi" "" "NSIS.Script"
;menu-name,submenu,icon
WriteRegStr HKCR "*\shell\NSIS.Script" "MUIVerb" "NSIS"
WriteRegStr HKCR "*\shell\NSIS.Script" "ExtendedSubCommandsKey" "NSIS.Script\W7Menu"
WriteRegStr HKCR "*\shell\NSIS.Script" "Icon" "$INSTDIR\makensisw.exe,1"
;menu-name,submenu entries,icon
WriteRegStr HKLM \
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
"MUIVerb" \
"NSIS"
WriteRegStr HKLM \
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
"SubCommands" \
"NSIS.compile;NSIS.compile-compressor"
WriteRegStr HKLM \
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
"Icon" \
"$INSTDIR\makensisw.exe,1"
""
;compile
;compile
WriteRegStr HKCR "NSIS.Script\W7Menu\shell\compile" "MUIVerb" "Compile NSIS Script"
WriteRegStr HKLM \
WriteRegStr HKCR "NSIS.Script\W7Menu\shell\compile\command" "" '"$INSTDIR\makensisw.exe" "%1"'
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile" \
"" \
"Compile NSIS Script"
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile\command" \
"" \
'"$INSTDIR\makensisw.exe" "%1"'
;compile (choose compressor)
;compile (choose compressor)
WriteRegStr HKCR "NSIS.Script\W7Menu\shell\compile-compressor" "MUIVerb" "Compile NSIS Script (Choose Compressor)"
WriteRegStr HKLM \
WriteRegStr HKCR "NSIS.Script\W7Menu\shell\compile-compressor\command" "" '"$INSTDIR\makensisw.exe" /ChooseCompressor "%1"'
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile-compressor" \
"" \
"Compile NSIS Script (Choose Compressor)"
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile-compressor\command" \
"" \
'"$INSTDIR\makensisw.exe" /ChooseCompressor "%1"'
;repeat for Unicode NSIS
;repeat for Unicode NSIS
IfFileExists "$INSTDIR\Unicode\makensisw.exe" 0 End
IfFileExists "$INSTDIR\Unicode\makensisw.exe" 0 End
;add separator above the next entry
;add separator above the next entry
WriteRegDWORD HKCR "NSIS.Script\W7Menu\shell\ucompile" "CommandFlags" "32"
WriteRegDWORD HKCR \
"NSIS.Script\W7Menu\shell\ucompile" \
"CommandFlags" \
"32"
;submenu entries
WriteRegStr HKLM \
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
"SubCommands" \
"NSIS.compile;NSIS.compile-compressor;NSIS.ucompile;NSIS.ucompile-compressor"
;compile unicode
;compile unicode
WriteRegStr HKCR "NSIS.Script\W7Menu\shell\ucompile" "MUIVerb" "Compile Unicode NSIS Script"
WriteRegStr HKLM \
WriteRegStr HKCR "NSIS.Script\W7Menu\shell\ucompile\command" "" '"$INSTDIR\Unicode\makensisw.exe" "%1"'
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile" \
"" \
"Compile Unicode NSIS Script"
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile\command" \
"" \
'"$INSTDIR\Unicode\makensisw.exe" "%1"'
;compile unicode (choose compressor)
;compile unicode (choose compressor)
WriteRegStr HKCR "NSIS.Script\W7Menu\shell\ucompile-compressor" "MUIVerb" "Compile Unicode NSIS Script (Choose Compressor)"
WriteRegStr HKLM \
WriteRegStr HKCR "NSIS.Script\W7Menu\shell\ucompile-compressor\command" "" '"$INSTDIR\Unicode\makensisw.exe" /ChooseCompressor "%1"'
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile-compressor" \
 
"" \
"Compile Unicode NSIS Script (Choose Compressor)"
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile-compressor\command" \
"" \
'"$INSTDIR\Unicode\makensisw.exe" /ChooseCompressor "%1"'
End:
End:
SectionEnd


SectionEnd</highlight-nsis>
Function .onInit
 
${If} ${RunningX64}
== Alternative Method ==
SetRegView 64
The [http://social.msdn.microsoft.com/Forums/en/windowsuidevelopment/thread/3ee4702a-f75a-4790-9332-e50f241efd6f MSDN forums] mention an alternative method for creating cascading menus. This will create keys in the CommandStore (HKLM) rather than in HKCR.
${EndIf}
FunctionEnd
</highlight-nsis>


== Links ==
== Links ==

Latest revision as of 09:52, 14 March 2013

Description

As of Windows 7, one can create cascading context menus through the registry.

Example Scripts

This example creates a cascaded context menu for the NSIS compiler, and if present also for the Unicode version of NSIS. The entries will be added to HKCR.

Name "NSIS Window 7 Context Menu"
OutFile "nsW7Menu.exe"
RequestExecutionLevel admin
 
InstallDir $PROGRAMFILES\NSIS
InstallDirRegKey HKLM Software\NSIS ""
 
; Pages
Page directory
Page instfiles
 
; Sections
Section ""
	WriteRegStr HKCR ".nsi" "" "NSIS.Script"
 
	;menu-name,submenu,icon
	WriteRegStr	HKCR \
			"NSIS.Script\shell\NSIS.W7Menu" \
			"MUIVerb" \
			"NSIS"
	WriteRegStr	HKCR \
			"NSIS.Script\shell\NSIS.W7Menu" \
			"ExtendedSubCommandsKey" \
			"NSIS.Script\W7Menu"
	WriteRegStr	HKCR \
			"NSIS.Script\shell\NSIS.W7Menu" \
			"Icon" \
			"$INSTDIR\makensisw.exe,1" 
	;compile
	WriteRegStr	HKCR \
			"NSIS.Script\W7Menu\shell\compile" \
			"MUIVerb" "Compile NSIS Script"				
	WriteRegStr	HKCR \
			"NSIS.Script\W7Menu\shell\compile\command" \
			"" \
			'"$INSTDIR\makensisw.exe" "%1"' 
	;compile (choose compressor)
	WriteRegStr	HKCR  \
			"NSIS.Script\W7Menu\shell\compile-compressor" \
			"MUIVerb" \
			"Compile NSIS Script (Choose Compressor)"				
	WriteRegStr	HKCR \
			"NSIS.Script\W7Menu\shell\compile-compressor\command" \
			"" \
			'"$INSTDIR\makensisw.exe" /ChooseCompressor "%1"' 
	;repeat for Unicode NSIS
	IfFileExists "$INSTDIR\Unicode\makensisw.exe" 0 End	
 
	;add separator above the next entry
	WriteRegDWORD	HKCR  \
			"NSIS.Script\W7Menu\shell\ucompile"  \
			"CommandFlags" \
			"32" 
	;compile unicode
	WriteRegStr	HKCR \
			"NSIS.Script\W7Menu\shell\ucompile" \
			"MUIVerb" \
			"Compile Unicode NSIS Script"				
	WriteRegStr	HKCR \
			"NSIS.Script\W7Menu\shell\ucompile\command" \
			"" \
			'"$INSTDIR\Unicode\makensisw.exe" "%1"' 
	;compile unicode (choose compressor)
	WriteRegStr	HKCR \
			"NSIS.Script\W7Menu\shell\ucompile-compressor" \
			"MUIVerb" \
			"Compile Unicode NSIS Script (Choose Compressor)"				
	WriteRegStr	HKCR \
			"NSIS.Script\W7Menu\shell\ucompile-compressor\command" \
			"" \
			'"$INSTDIR\Unicode\makensisw.exe" /ChooseCompressor "%1"' 
	End: 
SectionEnd

This alternative version will add the keys to the CommandStore of HKLM instead.

Name "NSIS Window 7 Context Menu"
OutFile "nsW7Menu-alt.exe"
RequestExecutionLevel admin
 
InstallDir $PROGRAMFILES\NSIS
InstallDirRegKey HKLM Software\NSIS ""
 
 
;Includes
!include "x64.nsh"
 
; Pages
Page directory
Page instfiles
 
; Sections
Section ""	
	WriteRegStr HKCR ".nsi" "" "NSIS.Script"
 
	;menu-name,submenu entries,icon
	WriteRegStr	HKLM \
			"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
			"MUIVerb" \
			"NSIS"			
	WriteRegStr	HKLM \
			"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
			"SubCommands" \
			"NSIS.compile;NSIS.compile-compressor"
	WriteRegStr	HKLM \
			"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
			"Icon" \
			"$INSTDIR\makensisw.exe,1"
			""	
	;compile
	WriteRegStr	HKLM \
			"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile" \
			"" \
			"Compile NSIS Script"			
	WriteRegStr	HKLM \
			"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile\command" \
			"" \
			'"$INSTDIR\makensisw.exe" "%1"'	
	;compile (choose compressor)
	WriteRegStr	HKLM \
			"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile-compressor" \
			"" \
			"Compile NSIS Script (Choose Compressor)"			
	WriteRegStr	HKLM \
			"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile-compressor\command" \
			"" \
			'"$INSTDIR\makensisw.exe" /ChooseCompressor "%1"'	
	;repeat for Unicode NSIS
	IfFileExists "$INSTDIR\Unicode\makensisw.exe" 0 End	
	;add separator above the next entry
	WriteRegDWORD	HKCR \
			"NSIS.Script\W7Menu\shell\ucompile" \
			"CommandFlags" \
			"32"	
	;submenu entries
	WriteRegStr	HKLM \
			"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
			"SubCommands" \
			"NSIS.compile;NSIS.compile-compressor;NSIS.ucompile;NSIS.ucompile-compressor"		
	;compile unicode
	WriteRegStr	HKLM \
			"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile" \
			"" \
			"Compile Unicode NSIS Script"			
	WriteRegStr	HKLM \
			"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile\command" \
			"" \
			'"$INSTDIR\Unicode\makensisw.exe" "%1"'	
	;compile unicode (choose compressor)
	WriteRegStr	HKLM \
			"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile-compressor" \
			"" \
			"Compile Unicode NSIS Script (Choose Compressor)"			
	WriteRegStr	HKLM \
			"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile-compressor\command" \
			"" \
			'"$INSTDIR\Unicode\makensisw.exe" /ChooseCompressor "%1"'
	End:
SectionEnd
 
Function .onInit
	${If} ${RunningX64} 
		SetRegView 64
	${EndIf}
FunctionEnd

Links

MSDN
NSIS Discussion