Use PowerShell to open regedit at a specific path or RegJump for PowerShell

12206559615_2b81475662_m
Even though PowerShell contains everything to read and write to the registry I still find myself quite frequently opening the registry editor (aka regedit.exe). Since navigating the tree manually can be quite time consuming I used to rely on RegJump developed by Mark Russinovich.
I was wondering if the same could be implemented using PowerShell and maybe even adding some features like opening multiple registry keys either from the clipboard or provided as an argument to the function.
Say hello to Open-Registry alias regJump. The function opens (instances of) the registry editor for provided paths from the clipboard or as argument to the regKey parameter. The registry paths can contain hive name shortnames like HKLM, HKCU, HKCR or PowerShell provider paths syntax like HKLM:\, HKCU:\.
Similar to how RegJump.exe handles non-existing paths Open-Registry also ignores those parts of the path and works its way backwards until it finds a valid path or returns an error message if the path doesn’t contain any valid parts.
Let’s look at some example use cases:

  1. Opening multiple instances of regedit at the specified paths via an argument to the regKey paramater:
    $testKeys =@'
    HKLM\Software\Microsoft\Outlook Express
    HKLM\Software\Microsoft\PowerShell
    HKLM\Software\Microsoft\Windows
    '@ -split "`r`n"
    Open-Registry $testKeys
    
  2. Same as above but the keys are no copied to the clipboard instead:
      @'
    HKLM\Software\Microsoft\Outlook Express
    HKLM\Software\Microsoft\PowerShell
    HKLM\Software\Microsoft\Windows
    '@ -split "`r`n" | clip
    Open-Registry
    
  3. The example will open regedit with the run key open as the last part of the path does not represent a key
    Open-Registry HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Skype
    
  4. The example provides an invalid path to the function (using the alias) resulting in a warning message and no instance of regedit opening
    regJump HKLMm\xxxxx
    

Further down below is the source code for the function without comment based help in order to reduce its screen size but the full version can be download from GitHub.
As usual when writing PowerShell I’ve learned one or the other thing along the way. This time I learned how to start a process and wait until its window is visible (this was necessary since otherwise regedit would launch all instances opened on the last path (when multiple paths were passed to the function)):

shareThoughts


Photo Credit: eLKayPics _ off via Compfight cc

Advertisements