Advertisement
AZJIO

JumpReg_CmdLine

Aug 15th, 2012
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.78 KB | None | 0 0
  1. #RequireAdmin
  2. ; En
  3. $LngMs1 = 'Message'
  4. $LngMs10 = 'Submitted text must contain a registry key'
  5. $LngMs5 = 'Error'
  6. $LngMs7 = 'Error: invalid name for the root registry key'
  7. $LngMs8 = 'The key does not exist. The nearest key is:'
  8. $LngMs9 = 'Do you want to jump to it?'
  9.  
  10. ; Ru
  11. ; если русская локализация, то русский язык
  12. If @OSLang = 0419 Then
  13.     $LngMs1 = 'Сообщение'
  14.     $LngMs10 = 'Переданный текст должен содержать раздел реестра'
  15.     $LngMs5 = 'Ошибка'
  16.     $LngMs7 = 'Ошибка имени корневого раздела'
  17.     $LngMs8 = 'Раздел не существует.' & @CRLF & 'Ближайший доступный раздел:'
  18.     $LngMs9 = 'Перейти в него?'
  19. EndIf
  20.  
  21. If $CmdLine[0] Then
  22.     $key = StringRegExpReplace($CmdLine[1], '(?s)[\[\s-]*(HK[^\]]+[^\]\s\\])[\]\s\\]*$', '\1') ; Wrapper для строки с [HK....] и с переносом строк
  23.     If @extended Then
  24.         _Jump($key)
  25.     Else
  26.         MsgBox(0, $LngMs1, $LngMs10)
  27.     EndIf
  28.     Exit
  29. EndIf
  30.  
  31. Func _Jump($sKey)
  32.     Local $hWnd, $hControl, $aKey, $i
  33.     If StringRight($sKey, 1) = '\' Then $sKey = StringTrimRight($sKey, 1)
  34.  
  35.     Switch StringMid($sKey, 3, 2)
  36.         Case 'LM'
  37.             $sKey = 'HKEY_LOCAL_MACHINE' & StringTrimLeft($sKey, 4)
  38.         Case 'U\'
  39.             $sKey = 'HKEY_USERS\' & StringTrimLeft($sKey, 4)
  40.         Case 'CU'
  41.             $sKey = 'HKEY_CURRENT_USER' & StringTrimLeft($sKey, 4)
  42.         Case 'CR'
  43.             $sKey = 'HKEY_CLASSES_ROOT' & StringTrimLeft($sKey, 4)
  44.         Case 'CC'
  45.             $sKey = 'HKEY_CURRENT_CONFIG' & StringTrimLeft($sKey, 4)
  46.     EndSwitch
  47.     ;проверяем существование раздела реестра
  48.     If Not _Reg_Exists($sKey) Then
  49.         Do
  50.             $sKey = StringRegExpReplace($sKey, '(.*)\\.*', '\1')
  51.             If Not @extended Then
  52.                 MsgBox(0, $LngMs5, $LngMs7)
  53.                 Return
  54.             EndIf
  55.         Until _Reg_Exists($sKey)
  56.         If MsgBox(4, $LngMs5, $LngMs8 & @CRLF & $sKey & @CRLF & @CRLF & $LngMs9) = 7 Then Return
  57.     EndIf
  58.  
  59.     _JumpRegistry($sKey)
  60. EndFunc
  61.  
  62. Func _JumpRegistry($sKey)
  63.     Local $hWnd, $hControl, $aKey, $i
  64.     If Not ProcessExists("regedit.exe") Then
  65.         Run(@WindowsDir & '\regedit.exe')
  66.         If Not WinWaitActive('[CLASS:RegEdit_RegEdit]', '', 3) Then Return
  67.     EndIf
  68.     If Not WinActive('[CLASS:RegEdit_RegEdit]') Then WinActivate('[CLASS:RegEdit_RegEdit]')
  69.  
  70.     $hWnd = WinGetHandle("[CLASS:RegEdit_RegEdit]")
  71.     $hControl = ControlGetHandle($hWnd, "", "[CLASS:SysTreeView32; INSTANCE:1]")
  72.  
  73.     $aKey = StringSplit($sKey, '\')
  74.     $sKey = '#0'
  75.     For $i = 1 To $aKey[0]
  76.         ControlTreeView($hWnd, "", $hControl, "Expand", $sKey)
  77.         $sKey &= '|' & $aKey[$i]
  78.     Next
  79.     ControlTreeView($hWnd, "", $hControl, "Expand", $sKey)
  80.     ControlTreeView($hWnd, "", $hControl, "Select", $sKey)
  81. EndFunc
  82.  
  83. Func _Reg_Exists($sKey)
  84.     RegRead($sKey, '')
  85.     Return Not (@error > 0)
  86. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement