Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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\""

share|improve this question
add comment

4 Answers

up vote 18 down vote accepted

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

share|improve this answer
3  
I don't understand what is meant by "For verbs that are none implies all". –  Colonel Panic Dec 17 '12 at 21:16
add comment

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)

share|improve this answer
    
Did you right click in the folder, or on the folder? –  Colonel Panic Dec 17 '12 at 21:16
add comment

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.

share|improve this answer
add comment

It is indeed hard to find what %V means or a list of those variables, through Google I have found that there seems to exist a %L too. I don't think you have to pass more than %V or %L though to a prompt, as there is no other useful information I think. Where %V could be the directory name, %L could be a location to a file. Doing an 'echo' could help when in doubt...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.