Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. function Open-Registry{
  2. [CmdletBinding()]
  3. [Alias("regJump")]
  4. param(
  5. [Parameter(Position=0)]
  6. $regKey
  7. )
  8. #check for clipbaord only if no argument provided
  9. if (!$regKey){
  10. #split the clipboard content by crlf and get of trailing crlf in case clipboard populated via piping it to clip.exe
  11. $cmd = {
  12. Add-Type -Assembly PresentationCore
  13. [Windows.Clipboard]::GetText() -split "`r`n" | where {$_}
  14. }
  15. #in case its run from the powershell commandline
  16. if([Threading.Thread]::CurrentThread.GetApartmentState() -eq 'MTA') {
  17. $regKey = & powershell -STA -Command $cmd
  18. }
  19. else {
  20. $regKey = & $cmd
  21. }
  22. }
  23. foreach ($key in $regKey){
  24. $replacers = @{
  25. 'HKCU:?\\'='HKEY_CURRENT_USER\'
  26. 'HKLM:?\\'='HKEY_LOCAL_MACHINE\'
  27. 'HKU:?\\'='HKEY_USERS\'
  28. 'HKCC:?\\'='HKEY_CURRENT_CONFIG\'
  29. 'HKCR:?\\'='HKEY_CLASSES_ROOT\'
  30. }
  31. #replace hive shortnames with or without PowerShell Syntax + remove trailing backslash
  32. $properKey = $key
  33. $replacers.GetEnumerator() | foreach {
  34. $properKey = $properKey.ToUpper() -replace $_.Key, $_.Value -replace '\\$'
  35. }
  36. #check if the path points to an existing key or its parent is an existing value
  37. #add one level since we don't want the first iteration of the loop to remove a level
  38. $path = "$properKey\dummyFolder"
  39. #test the registry path and revert to parent path until valid path is found otherwise return $false
  40. while(Split-Path $path -OutVariable path){
  41. $providerPath = $providerPath = "Registry::$path"
  42. if (Test-Path $providerPath){
  43. break
  44. }
  45. }
  46. if ($path){
  47. Set-ItemProperty HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\ -Name LastKey -Value $path -Force
  48. #start regedit using m switch to allow for multiple instances
  49. $regeditInstance = [Diagnostics.Process]::Start("regedit","-m")
  50. #wait the regedit window to appear
  51. while ($regeditInstance.MainWindowHandle -eq 0){
  52. sleep -Milliseconds 100
  53. }
  54. }
  55. else{
  56. Write-Warning "Neither ""$key"" nor any of its parents does exist"
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement