1 min read

Categories

Tags

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: [code language=”powershell”] $testKeys =@’ HKLM\Software\Microsoft\Outlook Express HKLM\Software\Microsoft\PowerShell HKLM\Software\Microsoft\Windows ‘@ -split “rn” Open-Registry $testKeys [/code]

  2. Same as above but the keys are no copied to the clipboard instead: [code language=”powershell”] @’ HKLM\Software\Microsoft\Outlook Express HKLM\Software\Microsoft\PowerShell HKLM\Software\Microsoft\Windows ‘@ -split “rn” | clip Open-Registry [/code]

  3. The example will open regedit with the run key open as the last part of the path does not represent a key [code language=”powershell”] Open-Registry HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Skype [/code]

  4. The example provides an invalid path to the function (using the alias) resulting in a warning message and no instance of regedit opening [code language=”powershell”] regJump HKLMm\xxxxx [/code]

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)): https://gist.github.com/54403d02c24e303cb5f1

https://gist.github.com/0fab3cb49ecbfa1a6460

shareThoughts


Photo Credit: eLKayPics _ off via Compfight cc