Skip to content

Instantly share code, notes, and snippets.

@jaka
Created December 11, 2018 07:31
Show Gist options
  • Save jaka/38f14935c92504f624d87b984e384422 to your computer and use it in GitHub Desktop.
Save jaka/38f14935c92504f624d87b984e384422 to your computer and use it in GitHub Desktop.
Function Set-Default_2([String]$Ext, [String]$Value)
{
$Classes = "HKLM:\SOFTWARE\Classes\"
$Path = Join-Path -Path $Classes -ChildPath $Ext
If (!(Test-Path -Path $Path))
{
New-Item -Path $Path
}
Set-ItemProperty -Path $Path -Name "(Default)" -Type String -Force -Value ($Value + $Ext)
}
Function Set-Handler($Extension)
{
$Classes = "HKLM:\SOFTWARE\Classes\"
$DefaultPath = "C:\Program Files\7-Zip\"
$DefaultCommand = """" + $DefaultPath + "7zFM.exe"" ""%1"""
$Handler = Join-Path -Path $Classes -ChildPath ($Value + $Extension["Ext"])
If (!(Test-Path -Path $Handler))
{
New-Item -Path $Handler
}
Set-ItemProperty -Path $Handler -Name "(Default)" -Type String -Value $Extension["Description"]
$DefaultIcon = Join-Path -Path $Handler -ChildPath "DefaultIcon"
If (!(Test-Path -Path $DefaultIcon))
{
New-Item -Path $DefaultIcon
}
Set-ItemProperty -Path $DefaultIcon -Name "(Default)" -Type String -Value ($DefaultPath + $Extension["DefaultIcon"])
$Command = Join-Path -Path $Handler -ChildPath "shell\open\command"
If (!(Test-Path -Path $Command))
{
New-Item -Force -Path $Command
}
Set-ItemProperty -Path $Command -Name "(Default)" -Type String -Value $DefaultCommand
}
$001 = @{
Ext = '.001'
Description = '001 Archive'
DefaultIcon = '7z.dll,9'
}
$7z = @{
Ext = ".7z"
Description = "7z Archive"
DefaultIcon = "7z.dll,0"
}
$bzip2 = @{
Ext = ".bzip2"
Description = "bzip2 Archive"
DefaultIcon = "7z.dll,2"
}
$zip = @{
Ext = ".zip"
Description = "Zip Archive"
DefaultIcon = "7z.dll,1"
}
$rar = @{
Ext = ".rar"
Description = "RAR Archive"
DefaultIcon = "7z.dll,3"
}
$cab = @{
Ext = ".cab"
Description = "CAB Archive"
DefaultIcon = "7z.dll,7"
}
$iso = @{
Ext = ".iso"
Description = "ISO Image"
DefaultIcon = "7z.dll,8"
}
<#
$ = @{
Ext = ""
Description = ""
DefaultIcon = ""
}
#>
$Value = "7-Zip"
$Extensions = @($001, $7z, $bzip2, $zip, $rar, $cab, $iso)
ForEach ($Extension in $Extensions)
{
Set-Default_2 -Ext $Extension["Ext"] -Value $Value
Set-Handler -Extension $Extension
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment