Skip to content

Instantly share code, notes, and snippets.

@eggbean
Last active April 1, 2026 02:27
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.
WinDirStat PowerShell script or registry file to add context menu entries to open on drives or folder, with a little icon. No longer needed with WinDirStat v2.
# 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
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\windirstat]
@="Open WinDirStat here"
"Icon"="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe,0"
[HKEY_CLASSES_ROOT\Directory\Background\shell\windirstat\command]
@="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe \"%V\""
[HKEY_CLASSES_ROOT\Directory\shell\windirstat]
@="Open WinDirStat here"
"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]
@="Open WinDirStat here"
"Icon"="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe,0"
[HKEY_CLASSES_ROOT\Drive\shell\windirstat\command]
@="C:\\Program Files (x86)\\WinDirStat\\windirstat.exe \"%1\\\""
@earthbound19
Copy link
Copy Markdown

This works, and (from a documentation / AI-assisted wiki search I did) the installer has an option to create context menus; maybe it didn't used to and maybe that's the implementation @opus-x refers to. So if the context menu is missing (as it was in my case), reinstalling the newest with that option may fix it.

@eggbean
Copy link
Copy Markdown
Author

eggbean commented Apr 1, 2026

@earthbound19 As far as I can remember there were no context menus when I did this, but they were added to WinDirStat v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment