Skip to content

Instantly share code, notes, and snippets.

@eggbean
Last active December 9, 2024 17:17
Show Gist options
  • Select an option

  • Save eggbean/315355ecdf17c41347e835ffafd08326 to your computer and use it in GitHub Desktop.

Select an option

Save eggbean/315355ecdf17c41347e835ffafd08326 to your computer and use it in GitHub Desktop.

Revisions

  1. eggbean revised this gist Aug 15, 2024. 1 changed file with 83 additions and 0 deletions.
    83 changes: 83 additions & 0 deletions windirstat-add-context-menu.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,83 @@
    # Adds shell integration for WinDirStat. The program should be installed in
    # Program Files (x86) but it will check if that directory is not on C:
    #
    # Alternatively, if installed on C: you can use the reg file below instead.

    if (-not ([security.principal.windowsprincipal][security.principal.windowsidentity]::getcurrent()).isinrole([security.principal.windowsbuiltinrole]::administrator)) {
    write-error "this script needs to be run as an administrator. please restart powershell as an administrator and try again."
    exit
    }

    new-psdrive -name hkcr -psprovider registry -root hkey_classes_root

    $windirstatpath = join-path ${env:programfiles(x86)} "windirstat\windirstat.exe"

    if ([string]::isnullorempty($windirstatpath) -or !(test-path $windirstatpath)) {
    write-error "windirstat not found at $windirstatpath. please check the installation path."
    exit
    }

    function add-registryentry {
    param (
    [string]$path,
    [hashtable]$properties
    )

    if (-not (test-path $path)) {
    new-item -path $path -force | out-null
    }

    foreach ($prop in $properties.getenumerator()) {
    set-itemproperty -path $path -Name $prop.Key -Value $prop.Value
    }
    }

    $registryEntries = @(
    @{
    Path = "HKCR:\Directory\Background\shell\windirstat"
    Properties = @{
    "(Default)" = "Open WinDirStat here"
    "Icon" = "$winDirStatPath,0"
    }
    },
    @{
    Path = "HKCR:\Directory\Background\shell\windirstat\command"
    Properties = @{
    "(Default)" = """$winDirStatPath"" ""%V"""
    }
    },
    @{
    Path = "HKCR:\Directory\shell\windirstat"
    Properties = @{
    "(Default)" = "Open WinDirStat here"
    "Icon" = "$winDirStatPath,0"
    }
    },
    @{
    Path = "HKCR:\Directory\shell\windirstat\command"
    Properties = @{
    "(Default)" = """$winDirStatPath"" ""%1"""
    }
    },
    @{
    Path = "HKCR:\Drive\shell\windirstat"
    Properties = @{
    "(Default)" = "Open WinDirStat here"
    "Icon" = "$winDirStatPath,0"
    }
    },
    @{
    Path = "HKCR:\Drive\shell\windirstat\command"
    Properties = @{
    "(Default)" = """$winDirStatPath"" ""%1\"""
    }
    }
    )

    foreach ($entry in $registryEntries) {
    Add-RegistryEntry -Path $entry.Path -Properties $entry.Properties
    }

    Write-Host "Registry entries for WinDirStat have been added successfully."

    Remove-PSDrive -Name HKCR
  2. eggbean revised this gist Aug 15, 2024. 1 changed file with 5 additions and 29 deletions.
    34 changes: 5 additions & 29 deletions windirstat-add-context-menu.reg
    Original file line number Diff line number Diff line change
    @@ -1,46 +1,22 @@
    Windows Registry Editor Version 5.00

    [-HKEY_CLASSES_ROOT\Directory\Background\shell\windirstat]

    [HKEY_CLASSES_ROOT\Directory\Background\shell\windirstat]
    @="Open WinDirStat here"

    [HKEY_CLASSES_ROOT\Directory\Background\shell\windirstat]
    "Icon"=hex(2):43,00,3A,00,5C,00,50,00,72,00,6F,00,67,00,72,00,61,00,6D,00,20,\
    00,46,00,69,00,6C,00,65,00,73,00,20,00,28,00,78,00,38,00,36,00,29,00,5C,00,\
    57,00,69,00,6E,00,44,00,69,00,72,00,53,00,74,00,61,00,74,00,5C,00,77,00,69,\
    00,6E,00,64,00,69,00,72,00,73,00,74,00,61,00,74,00,2E,00,65,00,78,00,65,00,\
    2C,00,30,00
    "Icon"="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe,0"

    [HKEY_CLASSES_ROOT\Directory\Background\shell\windirstat\command]
    @="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe \"%1\""

    [-HKEY_CLASSES_ROOT\Directory\shell\windirstat]
    @="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe \"%V\""

    [HKEY_CLASSES_ROOT\Directory\shell\windirstat]
    @="Open WinDirStat here"

    [HKEY_CLASSES_ROOT\Directory\shell\windirstat]
    "Icon"=hex(2):43,00,3A,00,5C,00,50,00,72,00,6F,00,67,00,72,00,61,00,6D,00,20,\
    00,46,00,69,00,6C,00,65,00,73,00,20,00,28,00,78,00,38,00,36,00,29,00,5C,00,\
    57,00,69,00,6E,00,44,00,69,00,72,00,53,00,74,00,61,00,74,00,5C,00,77,00,69,\
    00,6E,00,64,00,69,00,72,00,73,00,74,00,61,00,74,00,2E,00,65,00,78,00,65,00,\
    2C,00,30,00
    "Icon"="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe,0"

    [HKEY_CLASSES_ROOT\Directory\shell\windirstat\command]
    @="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe \"%1\""

    [-HKEY_CLASSES_ROOT\Drive\shell\windirstat]

    [HKEY_CLASSES_ROOT\Drive\shell\windirstat]
    @="Open WinDirStat here"

    [HKEY_CLASSES_ROOT\Drive\shell\windirstat]
    "Icon"=hex(2):43,00,3A,00,5C,00,50,00,72,00,6F,00,67,00,72,00,61,00,6D,00,20,\
    00,46,00,69,00,6C,00,65,00,73,00,20,00,28,00,78,00,38,00,36,00,29,00,5C,00,\
    57,00,69,00,6E,00,44,00,69,00,72,00,53,00,74,00,61,00,74,00,5C,00,77,00,69,\
    00,6E,00,64,00,69,00,72,00,73,00,74,00,61,00,74,00,2E,00,65,00,78,00,65,00,\
    2C,00,30,00
    "Icon"="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe,0"

    [HKEY_CLASSES_ROOT\Drive\shell\windirstat\command]
    @="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe \"%1\""
    @="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe \"%1\\\""
  3. eggbean created this gist Oct 6, 2023.
    46 changes: 46 additions & 0 deletions windirstat-add-context-menu.reg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    Windows Registry Editor Version 5.00

    [-HKEY_CLASSES_ROOT\Directory\Background\shell\windirstat]

    [HKEY_CLASSES_ROOT\Directory\Background\shell\windirstat]
    @="Open WinDirStat here"

    [HKEY_CLASSES_ROOT\Directory\Background\shell\windirstat]
    "Icon"=hex(2):43,00,3A,00,5C,00,50,00,72,00,6F,00,67,00,72,00,61,00,6D,00,20,\
    00,46,00,69,00,6C,00,65,00,73,00,20,00,28,00,78,00,38,00,36,00,29,00,5C,00,\
    57,00,69,00,6E,00,44,00,69,00,72,00,53,00,74,00,61,00,74,00,5C,00,77,00,69,\
    00,6E,00,64,00,69,00,72,00,73,00,74,00,61,00,74,00,2E,00,65,00,78,00,65,00,\
    2C,00,30,00

    [HKEY_CLASSES_ROOT\Directory\Background\shell\windirstat\command]
    @="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe \"%1\""

    [-HKEY_CLASSES_ROOT\Directory\shell\windirstat]

    [HKEY_CLASSES_ROOT\Directory\shell\windirstat]
    @="Open WinDirStat here"

    [HKEY_CLASSES_ROOT\Directory\shell\windirstat]
    "Icon"=hex(2):43,00,3A,00,5C,00,50,00,72,00,6F,00,67,00,72,00,61,00,6D,00,20,\
    00,46,00,69,00,6C,00,65,00,73,00,20,00,28,00,78,00,38,00,36,00,29,00,5C,00,\
    57,00,69,00,6E,00,44,00,69,00,72,00,53,00,74,00,61,00,74,00,5C,00,77,00,69,\
    00,6E,00,64,00,69,00,72,00,73,00,74,00,61,00,74,00,2E,00,65,00,78,00,65,00,\
    2C,00,30,00

    [HKEY_CLASSES_ROOT\Directory\shell\windirstat\command]
    @="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe \"%1\""

    [-HKEY_CLASSES_ROOT\Drive\shell\windirstat]

    [HKEY_CLASSES_ROOT\Drive\shell\windirstat]
    @="Open WinDirStat here"

    [HKEY_CLASSES_ROOT\Drive\shell\windirstat]
    "Icon"=hex(2):43,00,3A,00,5C,00,50,00,72,00,6F,00,67,00,72,00,61,00,6D,00,20,\
    00,46,00,69,00,6C,00,65,00,73,00,20,00,28,00,78,00,38,00,36,00,29,00,5C,00,\
    57,00,69,00,6E,00,44,00,69,00,72,00,53,00,74,00,61,00,74,00,5C,00,77,00,69,\
    00,6E,00,64,00,69,00,72,00,73,00,74,00,61,00,74,00,2E,00,65,00,78,00,65,00,\
    2C,00,30,00

    [HKEY_CLASSES_ROOT\Drive\shell\windirstat\command]
    @="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe \"%1\""
    Binary file added windirstat-context-menu.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.