Which special variables are available when writing a shell command for a context menu

A comment by Chris Guzak on the Extending Shortcut Menus MSDN article lists the various "command line variables" that are available:

%* – Replace with all parameters.

%~ – Replace with all parameters starting with and following the second parameter.

%0 or %1 – The first file parameter. For example "C:\Users\Eric\Desktop\New Text Document.txt". Generally this should be in quotes and the applications command line parsing should accept quotes to disambiguate files with spaces in the name and different command line parameters (this is a security best practice and I believe mentioned in MSDN).

%<n> (where <n> is 2-9) – Replace with the nth parameter.

%s – Show command.

%h – Hotkey value.

%i – IDList stored in a shared memory handle is passed here.

%l – Long file name form of the first parameter. Note that Win32/64 applications will be passed the long file name, whereas Win16 applications get the short file name. Specifying %l is preferred as it avoids the need to probe for the application type.

%d – Desktop absolute parsing name of the first parameter (for items that don't have file system paths).

%v – For verbs that are none implies all. If there is no parameter passed this is the working directory.

%w – The working directory.

So %L or %l should be preferred.

Also see http://www.robvanderwoude.com/ntstart.php


This question intrigued me so I did some experimenting. I have a folder C:\iso. What I found when I did the right-click thing:

D = C:\iso
H = 0
I = :115057472:7932
L = C:\iso
S = 1
V = C:\iso
W = C:\

I returned a different set of numbers on every try. H was always 0 and S was always 1. D, L, and V were all the target folder. W was the parent of the target folder. Anyone care to expand on this?

FYI: I used the following registry entries to test:

[HKEY_CLASSES_ROOT\Directory\shell\testcmd]
@="Test Command Window Directory"
[HKEY_CLASSES_ROOT\Directory\shell\testcmd\command]
@="cmd.exe /k \"echo %A`%B`%C`%D`%E`%F`%G`%H`%I`%J`%K`%L`%M`%N`%O`%P`%Q`%R`%S`%T`%U`%V`%W`%X`%Y`%Z\""

(The ` characters were used for delimiters)


Here is the arguments/syntax for cmd.exe

/k carries out the command specified by the following string so it executes the command pushd %V and since the only argument pushd accepts is a path it follows that %V a variable delivered by explorer that contains the path of the folder right clicked.