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

15

6

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.

schodge

Posted 2011-03-18T20:15:15.367

Reputation: 403

Answers

4

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).

Justin Roettger

Posted 2011-03-18T20:15:15.367

Reputation: 56

Is there a way to do as -o* does, but only if there's more than one file in the archive? As in, can I make it extract to the current directory if there's only one file or folder in the archive? – NightExcessive – 2016-06-26T00:18:16.867

Default in Windows 10 is "C:\Program Files\7-Zip\7zFM.exe" x "%1" -o* -aou so change the 7zFM to just 7z "C:\Program Files\7-Zip\7z.exe" x "%1" -o* -aou – jsherk – 2017-12-02T17:36:43.723

12

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:

  1. Start regedit as administrator
  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:\Program Files\7-Zip\7zG.exe x "%1" -o*

(you might have to adjust this to match the path of your 7-Zip 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.

haiggoh

Posted 2011-03-18T20:15:15.367

Reputation: 123

Lots has changed since this post, but it still works great ... for me, it was under 7z_auto_file, not 7-Zip.7z. All I did was change the existing "command" to C:\Program Files\7-Zip\7zG.exe x "%1" -o* and voila. – neokio – 2015-12-21T07:35:05.393

On Windows 10, I also didn't see the path until I associated at least one file with 7-Zip in the 7-Zip File Manager (via Tools -> Options... menu). – Chris Nolet – 2017-05-04T20:50:08.850

Anyone know why this no longer works on Windows 10? The paths seem to be the same, but I just get a black console window that closes immediately, and nothing is extracted. Tried all the methods in this thread. – Ryan Weiss – 2019-05-29T16:34:43.277

1I don't see that registry path. I'm on Windows 8 w/ 64-bit 7zip. – phillipwei – 2014-06-18T18:40:49.877

5

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.

afrazier

Posted 2011-03-18T20:15:15.367

Reputation: 21 316

Does %~dpn1 work in file associations? (It doesn't in Windows XP. Also, you forgot x for extension.) – user1686 – 2011-03-18T20:46:21.603

1@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 – 2011-03-18T20:48:08.067

Hm, good point. – user1686 – 2011-03-18T21:12:23.297

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 – 2011-03-25T01:43:45.443

You'll probably have to use a batch file. – afrazier – 2011-03-25T03:51:45.910

2

Here's PowerShell script I wrote based on @haiggoh's answer. Before you run it, you need to open 7-zip, go to Tools->Options and associate 7-zip with wanted file extensions. After that, run the following PowerShell script (with admin rights):

$7zInstallationFolder = 'C:\Program Files\7-Zip'
$reg = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::ClassesRoot, [Microsoft.Win32.RegistryView]::Default)
$subKeys = $reg.GetSubKeyNames() | where { $_ -match '7-Zip.' }
foreach ($keyName in $subKeys) {
    $key = $reg.OpenSubKey($keyName + '\shell\open\command', $true)
    $key.SetValue('', '"' + $7zInstallationFolder + '\7zG.exe" x "%1" -o*')
}

Of course, make sure that $7zInstallationFolder variable contains correct path to your 7-zip installation.

xx77aBs

Posted 2011-03-18T20:15:15.367

Reputation: 251

How to revert it? I uninstalling and reinstalling didn't work – Lombas – 2017-05-09T12:44:36.257

@Lombas try associating 7-zip again with those extensions, if it doesn't work remove registry keys and try it again. – xx77aBs – 2017-05-10T10:58:04.080

associating 7-zip again with the extensions worked. Thank you very much! – Lombas – 2017-05-12T10:49:10.177

0

Here is a .reg file that configures Extract to folder as the default behavior when double-clicking files with one of the following extensions - 7z/CAB/GZ/GZIP/RAR/TAR/ZIP. You could do it for other file extensions using the same approach. I prefer the Windows default behavior for ISO/VHD mounting, so I didn't change that, and 7-Zip supports many other file types that I don't commonly encounter so I didn't change it for those.

You can revert this by going into 7-Zip File Manager, Tools, Options, and change the file associations as desired.

I tested on Windows 10 x64/7-Zip 15.12 x64. Because it uses C:\Program Files for the path to 7-Zip, you definitely need x64 Windows + x64 7-Zip, but I only tested on Windows 10.

You will have the same right-click options as before, this only changes what happens when you double-click, and only for those seven file types (again, you could do this for other file types using the same approach).

If there is already a folder of that name, it will give you the same 7-Zip prompt you get normally, with options for Yes/Yes to All/Auto Rename/No/No to All.

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Classes.7z]
@="7-Zip.7z"
[HKEY_CURRENT_USER\SOFTWARE\Classes.cab]
@="7-Zip.cab"
[HKEY_CURRENT_USER\SOFTWARE\Classes.gz]
@="7-Zip.gz"
[HKEY_CURRENT_USER\SOFTWARE\Classes.gzip]
@="7-Zip.gzip"
[HKEY_CURRENT_USER\SOFTWARE\Classes.rar]
@="7-Zip.rar"
[HKEY_CURRENT_USER\SOFTWARE\Classes.tar]
@="7-Zip.tar"
[HKEY_CURRENT_USER\SOFTWARE\Classes.zip]
@="7-Zip.zip"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.7z]
@="7z Archive"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.7z\DefaultIcon]
@="C:\Program Files\7-Zip\7z.dll,0"
[HKEY_CLASSES_ROOT\7-Zip.7z\shell]
@="extract"
[HKEY_CLASSES_ROOT\7-Zip.7z\shell\extract]
@="Extract to Folder"
[HKEY_CLASSES_ROOT\7-Zip.7z\shell\extract\command]
@="\"C:\Program Files\7-Zip\7zG.exe\" x \"%1\" -o*"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.7z\shell\open]
@=""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.7z\shell\open\command]
@="\"C:\Program Files\7-Zip\7zFM.exe\" \"%1\""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.cab]
@="cab Archive"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.cab\DefaultIcon]
@="C:\Program Files\7-Zip\7z.dll,7"
[HKEY_CLASSES_ROOT\7-Zip.cab\shell]
@="extract"
[HKEY_CLASSES_ROOT\7-Zip.cab\shell\extract]
@="Extract to Folder"
[HKEY_CLASSES_ROOT\7-Zip.cab\shell\extract\command]
@="\"C:\Program Files\7-Zip\7zG.exe\" x \"%1\" -o*"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.cab\shell\open]
@=""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.cab\shell\open\command]
@="\"C:\Program Files\7-Zip\7zFM.exe\" \"%1\""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.gz]
@="gz Archive"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.gz\DefaultIcon]
@="C:\Program Files\7-Zip\7z.dll,14"
[HKEY_CLASSES_ROOT\7-Zip.gz\shell]
@="extract"
[HKEY_CLASSES_ROOT\7-Zip.gz\shell\extract]
@="Extract to Folder"
[HKEY_CLASSES_ROOT\7-Zip.gz\shell\extract\command]
@="\"C:\Program Files\7-Zip\7zG.exe\" x \"%1\" -o*"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.gz\shell\open]
@=""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.gz\shell\open\command]
@="\"C:\Program Files\7-Zip\7zFM.exe\" \"%1\""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.gzip]
@="gzip Archive"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.gzip\DefaultIcon]
@="C:\Program Files\7-Zip\7z.dll,14"
[HKEY_CLASSES_ROOT\7-Zip.gzip\shell]
@="extract"
[HKEY_CLASSES_ROOT\7-Zip.gzip\shell\extract]
@="Extract to Folder"
[HKEY_CLASSES_ROOT\7-Zip.gzip\shell\extract\command]
@="\"C:\Program Files\7-Zip\7zG.exe\" x \"%1\" -o*"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.gzip\shell\open]
@=""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.gzip\shell\open\command]
@="\"C:\Program Files\7-Zip\7zFM.exe\" \"%1\""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.rar]
@="rar Archive"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.rar\DefaultIcon]
@="C:\Program Files\7-Zip\7z.dll,3"
[HKEY_CLASSES_ROOT\7-Zip.rar\shell]
@="extract"
[HKEY_CLASSES_ROOT\7-Zip.rar\shell\extract]
@="Extract to Folder"
[HKEY_CLASSES_ROOT\7-Zip.rar\shell\extract\command]
@="\"C:\Program Files\7-Zip\7zG.exe\" x \"%1\" -o*"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.rar\shell\open]
@=""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.rar\shell\open\command]
@="\"C:\Program Files\7-Zip\7zFM.exe\" \"%1\""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.tar]
@="tar Archive"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.tar\DefaultIcon]
@="C:\Program Files\7-Zip\7z.dll,13"
[HKEY_CLASSES_ROOT\7-Zip.tar\shell]
@="extract"
[HKEY_CLASSES_ROOT\7-Zip.tar\shell\extract]
@="Extract to Folder"
[HKEY_CLASSES_ROOT\7-Zip.tar\shell\extract\command]
@="\"C:\Program Files\7-Zip\7zG.exe\" x \"%1\" -o*"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.tar\shell\open]
@=""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.tar\shell\open\command]
@="\"C:\Program Files\7-Zip\7zFM.exe\" \"%1\""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.zip]
@="zip Archive"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.zip\DefaultIcon]
@="C:\Program Files\7-Zip\7z.dll,1"
[HKEY_CLASSES_ROOT\7-Zip.zip\shell]
@="extract"
[HKEY_CLASSES_ROOT\7-Zip.zip\shell\extract]
@="Extract to Folder"
[HKEY_CLASSES_ROOT\7-Zip.zip\shell\extract\command]
@="\"C:\Program Files\7-Zip\7zG.exe\" x \"%1\" -o*"
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.zip\shell\open]
@=""
[HKEY_CURRENT_USER\SOFTWARE\Classes\7-Zip.zip\shell\open\command]
@="\"C:\Program Files\7-Zip\7zFM.exe\" \"%1\""

Craig

Posted 2011-03-18T20:15:15.367

Reputation: 412

0

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

user1686

Posted 2011-03-18T20:15:15.367

Reputation: 283 655