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.

2 Answers2

1

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.

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
  • 13,855