7-zip & Windows 7: Make “Extract to <folder>” default on double-click

I'm trying to find a way to make the action you can perform from the context menu, "Extract to <folder_same_as_file_name>" the default action when double-clicking the file instead of simply launching 7-zip. Is there a simple way to do this?

In the alternative, I gather I could try passing parameters into the following:

7z x <filename> -o<filename>

But I'm not sure how to set this up (how to pass the filename parameter, and can I do this directly or will I have to write a batch file instead and pass the filename to it? The latter I find irritatingly unelegant, but whatever works.

-

Unfortunately, afrazier's batch program method won't work; Windows doesn't handle opening multiple files like that. When you try to open multiple files with a program, Windows doesn't open a single instance of the program and pass the files as multiple arguments to that one instance. Instead, Windows opens many instances of the program (as many instances as there are files), passing one file to each instance. It would be nice if you could just use %* and pass a bunch of files to a single .bat, and have that .bat run a loop processing each file one at a time, but unfortunately you can only use %1 when setting these kinds of actions in the registry.

Someone with some time on their hands could write a program that uses a mutex object to check if there is another instance already running, and if there is, to pass it's file to that instance and then close, whereon the original instance will put that file in a queue and get to it once it's done processing its own file. a batch could do the trick using tasklist and find, too, but that's not as good of a solution as mutex.

Anyway, try this for your extract command registry value to get the right folder name:

"\path\to\7z.exe" x "%1" -o* -aou


This will create a new folder in the same directory as the source archive with the same name as the source archive (sans the file extension).

Also, I added the -aou switch to automatically avoid filename conflicts (7z will append a number to the end of a file instead prompting you whether you want to overwrite or whatever).

-
Works perfectly. Thanks! –  schodge May 4 '11 at 21:35

This thread has become a bit confusing because of contradicting answers (it took me quite some time to figure out which was the right solution) so I thought it might be a good idea to summarize the results from afrazier's and Justin Roettger's posts combinded with my own experiences:

2. Open HKEY_CLASSES_ROOT\7-Zip.7z
3. Under that key, expand the Shell sub-key
4. Set the (Default) value to the string extract
5. Create a new sub-key named extract
6. Set the (Default) value for the extract key to Extract to Folder
7. Create a new sub-key under extract named command
8. Set the (Default) value of the command key to:

C:\ProgramFiles\7-Zip\7zG.exe x "%1" -o*

(you might have to a adjust this to match the path of you 7zip installation)

Instead of 7z with -aou like Justin Roettger suggested I ended up using 7zG, because this way you can choose to overwrite if you like just like extracting with the normal context menu.

That's it! 7z files are now extracted to a folder with their own name by double click. For other extensions like .rar and .zip you need to repeat these steps for the according keys. (i.e. HKEY_CLASSES_ROOT\7-Zip.rar and HKEY_CLASSES_ROOT\7-Zip.zip and so on)

Oh and to clarify: It does work with multiple files selected as well. No batch file need.

-
I don't see that registry path. I'm on Windows 8 w/ 64-bit 7zip. –  phillipwei Jun 18 at 18:40

The easy way

Install ExtractNow. You can configure it to do exactly what you want.

The hard way

Manual registry modification as follows...

• Start regedit as administrator

• Open HKCR\.7z and look at the (Default) value. Take note of what that is (in my case, as a PowerArchiver user, it's PASZIP)

• Go to the registry key in HKCR named that. (in my case HKCR\PASZIP)

• Under that key, expand the Shell sub-key

• Set the (Default) value to the string extract

• Create a new sub-key named extract

• Set the (Default) value for the extract key to Extract to Folder

• Create a new sub-key under extract named command

• Set the (Default) value of the command key to

C:\Program Files\7-Zip\7zG.exe x "%1" -o* -aou


(you might have to adjust the path)

Thanks to Justin Roettger for pointing out the correct name variable needed for this.

That should be it. Now 7z files are extracted to a folder with their own name by double click. For other extensions like .rar and .zip you need to repeat this steps for the according keys.

If you only want to make the changes on your user account instead of system-wide, modify HKCU\Software\Classes instead of HKCR. HKCR is a virtual key that's a union of HKLM\Software\Classes and HKCU\Software\Classes where the data in your account (HKCU) overrides the system-wide data (HKLM). Normally running regedit as an Administrator means that modifying HKCR alters system-wide data in HKLM.

Extracting multiple files

Of course, this won't work if you have multiple files selected. If you want that to work, you need to create the following batch file:

@echo off
:top
if "%1"=="" goto :EOF
7z.exe x "%1" -o"%~dpn1"
shift
goto top


Now, follow the instructions above. In the very last step, set the (Default) value of the command key to C:\Path\To\File.bat %*

All of the registry modifications are untested from memory, but should be correct.

-
Does %~dpn1 work in file associations? (It doesn't in Windows XP. Also, you forgot x for extension.) –  grawity Mar 18 '11 at 20:46
@grawity: You don't want the x in the output folder name. As for it working... That's a good question. I'll edit to address... –  afrazier Mar 18 '11 at 20:48
Hm, good point. –  grawity Mar 18 '11 at 21:12
So close, but not quite there yet. After playing with the code both afrazier and grawity provided, I have the default key value set as "C:\Program Files\7-Zip\7z.exe" x "%1" -o"%~dpn1" I wasn't getting any benefit from running cmd.exe that I could tell, and 7-zip's default open didn't bother with it. However, this is just unzipping to %~dpn1 in the same folder as the zip file. The \"%1.d\" gives a \filename.zip.d\ subdirectory in the same folder as the zip file, so it's closer, but not stripping off the extension. I've tried hybrids of the two, no luck. Any other suggestions? –  schodge Mar 25 '11 at 1:43
You'll probably have to use a batch file. –  afrazier Mar 25 '11 at 3:51

Pass parameters like this:

7z x "%1" -o"%1.d"


I recall hearing complaints about Windows 7 not allowing to directly edit file actions. I don't know if this is true or not... but if it is, save the following as a *.reg file and import it.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\7-Zip.7z\shell\extract]
@="Extract to folder"

[HKEY_CURRENT_USER\Software\Classes\7-Zip.7z\shell\extract\command]
@="7z.exe x \"%1\" -o\"%1.d\""

-