1

I use 7-Zip in a portable way on various different systems and inside Windows Sandbox so the associations are missing every time I start on those systems. I can go to 7-Zip > Tools > Options > Press the "+" button to associate, and then go to the Options > 7-Zip tab and check "Integrate 7-Zip in shell context menu". However, it would be very convenient if there was a way to automate this.

Ideally, I would like to do this in PowerShell as part of a script that I use to adjust UI options when I am working on various servers, such that:

if (Test-Path "$SevenZipPath\7zFM.exe") { 
    # Add the 7-Zip menu into the File Explorer right-click context menu
    # Apply associations for all 7-Zip supported file types
}

Is there a way to a) add the 7-Zip shell context menu, and b) apply all associations to 7-Zip?

I find clues to a) here (but for Visual Studio Code). It would be good to have an equivalent for 7-Zip.

File associations for b) might be harder as on searching for how to do that in general, most answers are broken and various sites suggest that ftype / assoc stopped working due to a Windows Update around 2020 and never started worked again. It would be good to have a reliable/generic method that allows associating file types in Windows (how 7-Zip internally creates these associations is a mystery).

YorSubs
  • 3,194
  • 7
  • 37
  • 60
  • You may look at the registry table of the [MSI](https://www.7-zip.org/a/7z2201-x64.msi) to see what it's doing. From a quick look using the InstEd tool, only the context menu extension is registered this way. The file associations are registered by the app itself, but this isn't anything special you should find general information how to register file types using PowerShell. – zett42 Oct 09 '22 at 08:46
  • For finding out file types registry keys you could use a tool like Regshot that captures the registry before and after associating file types within 7-zip. – zett42 Oct 09 '22 at 08:58
  • As above, every site that I've looked at for file association offers a way (using `ftype` and `assoc`) that is broken. On investigation, people have stated that a Windows Update around 2019 / 2020 broke this functionality and I've not found anything newer that is working model for doing this at all in Windows. RegShot is a good idea; I have it here and will do a capture on that. – YorSubs Oct 09 '22 at 09:14

1 Answers1

1

You can manually create file associations in the registry with Set-ItemProperty inside HKCU (if you use HKLM you will need to restart explorer.exe or the system to take effect)

Installing a context menu manually is much the same as adding file extensions. The registry modifications will be more application specific - but you can use Process Explorer to examine how 7zfm does it. To do this run Process Explorer(as admin), set a filter to only show registry access from 7zfm.exe, then launch 7zfm.exe(also as admin) configure as required and close 7zfm - observe results in Process Explorer - and create the keys as required.

Also possible dirty hack - 7zfm will only install file associations when run as administrator - you might be able to fake that with Start-Process, Start-Sleep and Stop-Process?

MisterSmith
  • 2,884
  • 1
  • 10
  • 13