Windows 7 Cascading Context Menu: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
Line 17: Line 17:
; Sections
; Sections
Section ""
Section ""
WriteRegStr HKCR ".nsi" "" "NSIS.Script"
;menu-name,submenu,icon
;menu-name,submenu,icon
WriteRegStr HKCR \
WriteRegStr HKCR \
"NSIS.Script\shell\NSIS.W7Menu" \
"NSIS.Script\shell\NSIS.W7Menu" \
"MUIVerb" \
"MUIVerb" \
"NSIS"
"NSIS"
WriteRegStr HKCR \
WriteRegStr HKCR \
"NSIS.Script\shell\NSIS.W7Menu" \
"NSIS.Script\shell\NSIS.W7Menu" \
"ExtendedSubCommandsKey" \
"ExtendedSubCommandsKey" \
"NSIS.Script\W7Menu"
"NSIS.Script\W7Menu"
WriteRegStr HKCR \
WriteRegStr HKCR \
"NSIS.Script\shell\NSIS.W7Menu" \
"NSIS.Script\shell\NSIS.W7Menu" \
"Icon" \
"Icon" \
"$INSTDIR\makensisw.exe,1"
"$INSTDIR\makensisw.exe,1"  
;compile
;compile
WriteRegStr HKCR \
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\compile" \
"NSIS.Script\W7Menu\shell\compile" \
"MUIVerb" "Compile NSIS Script"
"MUIVerb" "Compile NSIS Script"
WriteRegStr HKCR \
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\compile\command" \
"NSIS.Script\W7Menu\shell\compile\command" \
"" \
"" \
'"$INSTDIR\makensisw.exe" "%1"'
'"$INSTDIR\makensisw.exe" "%1"'  
;compile (choose compressor)
;compile (choose compressor)
WriteRegStr HKCR  \
WriteRegStr HKCR  \
"NSIS.Script\W7Menu\shell\compile-compressor" \
"NSIS.Script\W7Menu\shell\compile-compressor" \
"MUIVerb" \
"MUIVerb" \
"Compile NSIS Script (Choose Compressor)"
"Compile NSIS Script (Choose Compressor)"
WriteRegStr HKCR \
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\compile-compressor\command" \
"NSIS.Script\W7Menu\shell\compile-compressor\command" \
"" \
"" \
'"$INSTDIR\makensisw.exe" /ChooseCompressor "%1"'
'"$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  \
WriteRegDWORD HKCR  \
"NSIS.Script\W7Menu\shell\ucompile"  \
"NSIS.Script\W7Menu\shell\ucompile"  \
"CommandFlags" \
"CommandFlags" \
"32"
"32"  
;compile unicode
;compile unicode
WriteRegStr HKCR \
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\ucompile" \
"NSIS.Script\W7Menu\shell\ucompile" \
"MUIVerb" \
"MUIVerb" \
"Compile Unicode NSIS Script"
"Compile Unicode NSIS Script"
WriteRegStr HKCR \
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\ucompile\command" \
"NSIS.Script\W7Menu\shell\ucompile\command" \
"" \
"" \
'"$INSTDIR\Unicode\makensisw.exe" "%1"'
'"$INSTDIR\Unicode\makensisw.exe" "%1"'  
;compile unicode (choose compressor)
;compile unicode (choose compressor)
WriteRegStr HKCR \
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\ucompile-compressor" \
"NSIS.Script\W7Menu\shell\ucompile-compressor" \
"MUIVerb" \
"MUIVerb" \
"Compile Unicode NSIS Script (Choose Compressor)"
"Compile Unicode NSIS Script (Choose Compressor)"
WriteRegStr HKCR \
WriteRegStr HKCR \
"NSIS.Script\W7Menu\shell\ucompile-compressor\command" \
"NSIS.Script\W7Menu\shell\ucompile-compressor\command" \
"" \
"" \
'"$INSTDIR\Unicode\makensisw.exe" /ChooseCompressor "%1"'
'"$INSTDIR\Unicode\makensisw.exe" /ChooseCompressor "%1"'  
End:  
End:
SectionEnd</highlight-nsis>
SectionEnd</highlight-nsis>


Line 101: Line 91:


; Sections
; Sections
Section ""
Section ""
WriteRegStr HKCR ".nsi" "" "NSIS.Script"
;menu-name,submenu entries,icon
;menu-name,submenu entries,icon
Line 107: Line 98:
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
"MUIVerb" \
"MUIVerb" \
"NSIS"
"NSIS"
WriteRegStr HKLM \
WriteRegStr HKLM \
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
Line 116: Line 106:
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
"Icon" \
"Icon" \
"$INSTDIR\makensisw.exe,1"
"$INSTDIR\makensisw.exe,1"
WriteRegStr HKLM \
WriteRegStr HKLM \ "SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu\command" \
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu\command" \
"" \
"" \
""
""
;compile
;compile
WriteRegStr HKLM \
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile" \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile" \
"" \
"" \
"Compile NSIS Script"
"Compile NSIS Script"
WriteRegStr HKLM \
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile\command" \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile\command" \
"" \
"" \
'"$INSTDIR\makensisw.exe" "%1"'
'"$INSTDIR\makensisw.exe" "%1"'
;compile (choose compressor)
;compile (choose compressor)
WriteRegStr HKLM \
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile-compressor" \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile-compressor" \
"" \
"" \
"Compile NSIS Script (Choose Compressor)"
"Compile NSIS Script (Choose Compressor)"
WriteRegStr HKLM \
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile-compressor\command" \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.compile-compressor\command" \
"" \
"" \
'"$INSTDIR\makensisw.exe" /ChooseCompressor "%1"'
'"$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 \
WriteRegDWORD HKCR \
"NSIS.Script\W7Menu\shell\ucompile" \
"NSIS.Script\W7Menu\shell\ucompile" \
"CommandFlags" \
"CommandFlags" \
"32"
"32"
;submenu entries
;submenu entries
WriteRegStr HKLM \
WriteRegStr HKLM \
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu" \
"SubCommands" \
"SubCommands" \
"NSIS.compile;NSIS.compile-compressor;NSIS.ucompile;NSIS.ucompile-compresso"
"NSIS.compile;NSIS.compile-compressor;NSIS.ucompile;NSIS.ucompile-compressor"
;compile unicode
;compile unicode
WriteRegStr HKLM \
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile" \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile" \
"" \
"" \
"Compile Unicode NSIS Script"
"Compile Unicode NSIS Script"
WriteRegStr HKLM \
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile\command" \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile\command" \
"" \
"" \
'"$INSTDIR\Unicode\makensisw.exe" "%1"'
'"$INSTDIR\Unicode\makensisw.exe" "%1"'
;compile unicode (choose compressor)
;compile unicode (choose compressor)
WriteRegStr HKLM \
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile-compressor" \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile-compressor" \
"" \
"" \
"Compile Unicode NSIS Script (Choose Compressor)"
"Compile Unicode NSIS Script (Choose Compressor)"
WriteRegStr HKLM \
WriteRegStr HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile-compressor\command" \
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\NSIS.ucompile-compressor\command" \
"" \
"" \
'"$INSTDIR\Unicode\makensisw.exe" /ChooseCompressor "%1"'
'"$INSTDIR\Unicode\makensisw.exe" /ChooseCompressor "%1"'
End:
End:
 
SectionEnd</highlight-nsis>
SectionEnd
</highlight-nsis>


== Alternative Method ==
== Alternative Method ==

Revision as of 11:19, 14 September 2011

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 ""
 
; 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"	
	WriteRegStr	HKLM \
			"SOFTWARE\Classes\NSIS.Script\shell\NSIS.W7Menu\command" \
			"" \
			""	
	;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

Alternative Method

The MSDN forums mention an alternative method for creating cascading menus. This will create keys in the CommandStore (HKLM) rather than in HKCR.

Links

MSDN
NSIS Discussion