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

command linewindowswindows 7windows-registry

When extending the Windows' shell context menu (e.g. for adding an 'Open command here' prompt on directories), a 'command' key needs to be created in the registry.

The value of this 'command' key apparently can be any valid command line.

I want to know which 'special variables' are available for use inside this command line.

For example, I use following command for opening a cmd window from within a directory's context menu (*):

cmd.exe /e:on /f:on /s /k pushd "%V"


I cannot find any reference to what %V actually means or what the full list of such variables is.

(*)
Following registry keys are created for this:

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\cmdshell]
@=Open Command Prompt Here"

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\cmdshell\command]
@="cmd.exe /e:on /f:on /s /k pushd \"%V\""


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.