1

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

[HKEY_CLASSES_ROOT\exefile\shell\extract]
"MUIVerb"="Extract to SubDir"

[HKEY_CLASSES_ROOT\exefile\shell\innoex\command]
@="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 Jun 21 '20 at 01:10
  • @WasifHasan that extracts to a directory called `Foo.exe1`, I need a directory named `Foo` – George Hovhannisian Jun 21 '20 at 01:17
  • Then replace `%d1` with `%dpn1`? – Wasif Jun 21 '20 at 01:27
  • 1
    @WasifHasan Again, tried that, extracts to `Foo.exepn1`, And `%d` doesn't extract at all. – George Hovhannisian Jun 21 '20 at 02:02
  • 1
    **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 '20 at 14:51
  • @JosefZ edited the question. In the meantime, I have resorted to calling my batch file from the registry, which works exactly as I want it to. But that's not a solution, that's a workaround. – George Hovhannisian Jun 21 '20 at 22:18
  • 1
    Does this answer your question? [Which special variables are available when writing a shell command for a context menu](https://superuser.com/questions/136838/which-special-variables-are-available-when-writing-a-shell-command-for-a-context) – JosefZ Jun 23 '20 at 08:41
  • 1
    @JosefZ If it's the full list of parameters supported in the registry, then yes, but it's too small of a list to be complete. That answer is referencing a comment from the old MSDN website. Note, that the article itself does not list those.. There has to be some sort of documentation, listing _all_ the possible parameters. – George Hovhannisian Jun 23 '20 at 20:29

2 Answers2

0

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

[HKEY_CLASSES_ROOT\exefile\shell\extract]
"MUIVerb"="Extract to SubDir"

[HKEY_CLASSES_ROOT\exefile\shell\innoex\command]
@="D:\\Programs\\extractor\\extract.exe \"%1\" -o \"%w\""
;                                               ↑         unclear: -o or -d?

Explanation

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...");
    std::getchar();
    exit(-999 - argc);  /* exitcode to OS = ( -1000 -supplied_paramaters_count ) */
    return 0;
}
JosefZ
  • 12,837
  • 5
  • 37
  • 69
  • 1
    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 '20 at 05:26
  • 1
    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 '20 at 07:49
0

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.

If you select multiple files, Shell runs separate command line commands for each file. It calls as many programs as files selected, and passes them %1 parameter which is full path to that file.

ScienceDiscoverer
  • 322
  • 1
  • 3
  • 11