Wednesday, July 18, 2007

Instant Regedit access

This is a variation of an older post Open In Regedit (IE Context Menu) . This helps when you navigate the registry provider and you want to open regedit in the current key your working on.

Regedit maintains the last opened key under HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey subkey, and it automatically updates this subkey each time you close regedit.

We can takes advantage of that by updating the value of the key from PowerShell and then run regedit. To run the function simply pass it the $pwd variable. To reuse it, included it in your profile.

##### jump to regedit.exe in a specified key path ######

function jump-regedit{
param( [string]$path = $(throw "Please provide Path.") )
# close regedit if open
stop-process -n regedit -ea silentlycontinue
$regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit";
# sp = Set-ItemProperty
# iex = Invoke-Expression sp $regKey -name "LastKey" -value "My Computer\$(convert-path $path)";
iex "regedit.exe";
}
set-alias jreg jump-regedit
 

function Jump-Regedit{
    Stop-Process -name regedit -errorAction silentlycontinue
    $regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit"
    Set-ItemProperty $regKey -name LastKey -value "My Computer\$(convert-path $pwd)"
    regedit.exe
}

set-alias jreg jump-regedit

 

#### USAGE ####

PS HKLM:\SOFTWARE\Microsoft> jreg
 

Shay

No comments: