I have a command line application I use fore extracting files. Currently I'm using a batch file, but I have to drag-and-drop each file onto the batch file, so I want to add a context menu item for ease of use.

My batch file looks like this:

extract "%~1" -o "%~dpn1"

extract extracts and archive or and sfx archive (exe) -o sets the output directory.

This is what my registry looks like:

Windows Registry Editor Version 5.00

"MUIVerb"="Extract to SubDir"

@="D:\\Programs\\extractor\\extract.exe \"%~1\" -o \"%~dpn1\""

The ~ signs are, apparently, not recognized here, so I removed them and it worked, except not the way I wanted it to.

Foo.exe gets extracted to a directory called Foo.exepn1.

So I changed the command to:

extract "%1" -o "%d"

This, however doesn't work at all.

So, instead of trying out to see what works from the registry, I need the correct syntax that will work. I've been browsing MSDN for a while now, but I can't find the answer.

Bonus question: %1 presumes first command passed. Can I pass more than 1? i.e. can I select multiple files and extract them one AFTER the other? Currently, I see multiple command line windows, all extracting at the same time.

  • Shouldn't this be extract "%1" -o "%d1"? – Wasif Hasan Jun 21 at 1:10
  • @WasifHasan that extracts to a directory called Foo.exe1, I need a directory named Foo – George Hovhannisian Jun 21 at 1:17
  • Then replace %d1 with %dpn1? – Wasif Hasan Jun 21 at 1:27
  • @WasifHasan Again, tried that, extracts to Foo.exepn1, And %d doesn't extract at all. – George Hovhannisian Jun 21 at 2:02
  • 1. What is extract and what's its -o parameter meaning? where /R c:\ extract returns INFO: Could not find files for the given pattern(s). 2. Please edit the question and share the context menu item from registry. – JosefZ Jun 21 at 14:51

Use extract.exe "%1" -o "%w" (or extract.exe "%1" -o "%w\" if the extract.exe tool insists upon a trailing backslash for a directory path) as follows:

Windows Registry Editor Version 5.00

"MUIVerb"="Extract to SubDir"

@="D:\\Programs\\extractor\\extract.exe \"%1\" -o \"%w\""
;                                               ↑         unclear: -o or -d?


Long ago, I tested

  • all possible parameters for a shell context menu as well as
  • how cmd command line parameters are parsed and passed to an (console application) executable.

Parameters for a shell context menu test (in very truth, I tried all ciphers as well as all upper- and lower-case letters at that time). The final setting is as follows:

reg query "HKEY_CLASSES_ROOT\*\shell\CliParser Shell Params Test Exe\Command"

HKEY_CLASSES_ROOT\*\shell\CliParser Shell Params Test Exe\Command
    (Default)    REG_SZ    D:\bat\cliParserPause.exe "1 %1" "0 %0" "V %V" "L %L" "d %d" "w %w" "* %*" "s %s" "i %i" "h %h"

The same setting in terms of exported registry key:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\CliParser Shell Params Test Exe]

[HKEY_CLASSES_ROOT\*\shell\CliParser Shell Params Test Exe\Command]
@="D:\\bat\\cliParserPause.exe \"1 %1\" \"0 %0\" \"V %V\" \"L %L\" \"d %d\" \"w %w\" \"* %*\" \"s %s\" \"i %i\" \"h %h\""

Sample result from a right-click menu for a particular file:

param 0 = D:\bat\cliParserPause.exe
param 1 = 1 D:\temp\FOLDER 1\PROGRAMS\pro.exe
param 2 = 0 D:\temp\FOLDER 1\PROGRAMS\pro.exe
param 3 = V D:\temp\FOLDER 1\PROGRAMS\pro.exe
param 4 = L D:\temp\FOLDER 1\PROGRAMS\pro.exe
param 5 = d D:\temp\FOLDER 1\PROGRAMS\pro.exe
param 6 = w D:\temp\FOLDER 1\PROGRAMS
param 7 = *
param 8 = s 1
param 9 = i :344935344:4268
param 10 = h 0
press any key to continue...

The Win32 Console Application cliParserPause.exe source code is defined as follows:

#include "stdafx.h"
#include <wchar.h>
#include <cstdio>
#include <stdlib.h>

int main(int argc, wchar_t* argv[])
    for (int i = 0; i < argc; ++i)
        wprintf(L"param %d = %S\n", i, argv[i]);
    wprintf(L"press any key to continue...");
    exit(-999 - argc);  /* exitcode to OS = ( -1000 -supplied_paramaters_count ) */
    return 0;
| improve this answer | |
  • OK. That solves my actual problem, but it doesn't answer the question I posted. Where is that %w documented? I'm looking for some documentation listing all of those parameters, that I can pass from registry. So far, I can't find anything. – George Hovhannisian Jun 23 at 5:26
  • Actually, upon second glance, it doesn't even solve my problem. I would need to extarct to D:\temp\FOLDER 1\PROGRAM\pro not D:\temp\FOLDER 1\PROGRAMS or even `D:\temp\FOLDER 1\PROGRAMS\pro.exe` – George Hovhannisian Jun 23 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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