Skip to content

Instantly share code, notes, and snippets.

@awakecoding
Created December 12, 2023 03:27
Show Gist options
  • Save awakecoding/71ce70e7ac3b3058d4bfae250f69f54e to your computer and use it in GitHub Desktop.
Save awakecoding/71ce70e7ac3b3058d4bfae250f69f54e to your computer and use it in GitHub Desktop.
function Install-DbgHelp {
param (
[Parameter(Mandatory=$true, Position=0)]
[string] $DbgHelpBaseDir,
[Parameter()]
[string[]] $DbgHelpFiles = @('dbghelp.dll','symsrv.dll','srcsrv.dll'),
[Parameter()]
[switch] $Cleanup
)
$WinSdkTemp = "$Env:TEMP\winsdk"
$WinSdkSetupExe = "$WinSdkTemp\winsdksetup.exe"
$WinSdkSetupUrl = "https://go.microsoft.com/fwlink/?linkid=2120843"
New-Item -Path $WinSdkTemp -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
Invoke-WebRequest -Uri $WinSdkSetupUrl -OutFile $WinSdkSetupExe -UseBasicParsing
$WinSdkLayoutDir = "$WinSdkTemp\layout"
$WinSdkSetupLogFile = "$WinSdkTemp\winsdksetup.log"
Start-Process -FilePath $WinSdkSetupExe -ArgumentList @(
'/features', 'OptionId.WindowsDesktopDebuggers',
'/q', '/norestart',
'/layout', $WinSdkLayoutDir,
'/l', $WinSdkSetupLogFile) -Wait
$WinSdkExtractDir = "$WinSdkTemp\extract"
Get-Item "$WinSdkLayoutDir\Installers\*.msi" | ForEach-Object {
Start-Process -FilePath msiexec -ArgumentList @('/a', "`"$($_.FullName)`"",
'/qb', "TARGETDIR=`"$WinSdkExtractDir`"") -Wait
}
$WinSdkDebuggersDir = "$WinSdkExtractDir\Windows Kits\10\Debuggers"
Get-Item "$WinSdkDebuggersDir\*\dbghelp.dll" | ForEach-Object {
$Source = $_.Directory
$Architecture = $_.Directory.Name
$Destination = "$DbgHelpBaseDir\$Architecture"
New-Item -Path $Destination -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
$DbgHelpFiles | ForEach-Object {
Copy-Item (Join-Path $Source $_) (Join-Path $Destination $_)
}
}
if ($Cleanup) {
Remove-Item -Path $WinSdkTemp -Recurse -Force | Out-Null
}
}
# Install-DbgHelp "C:\DbgHelp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment