From 41465392e84503434db17d7569ef226e30975acc Mon Sep 17 00:00:00 2001 From: Corbin Date: Sat, 18 Apr 2026 08:41:31 -0400 Subject: [PATCH] Add `Get-userRegistryPath` example script --- windows/Get-UserRegistryPath.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 windows/Get-UserRegistryPath.ps1 diff --git a/windows/Get-UserRegistryPath.ps1 b/windows/Get-UserRegistryPath.ps1 new file mode 100644 index 0000000..1a87d3d --- /dev/null +++ b/windows/Get-UserRegistryPath.ps1 @@ -0,0 +1,16 @@ +$Username = ((Get-CimInstance win32_computersystem | ForEach-Object username) -split '\\')[1] +Write-Host "Signed in user is '$Username'" + +# Map PSDrive for HKU +New-PSDrive -Name HKU -PSProvider Registry -Root hkey_users | Out-Null + +# Find matching Volatile Env +try { + $Environment = ((Get-ItemProperty 'HKU:\*\Volatile Environment' | Where-Object Username -eq $Username).PSPath -split '\\')[2] + $UserRegistryPath = Join-Path -Path 'HKU:' -ChildPath $Environment +} catch [System.Security.SecurityException] { + Write-Error "Permission Denied" + throw System.Security.SecurityException +} + +Write-Host "User registry path is '$UserRegistryPath'" \ No newline at end of file