{************************************************************************/ /*函数名: pro_JumpToKey(const str_param_Root:string; const str_param_KeyPath:string; const str_param_ValueName:string) ; /*功能: 注册表定位 /*参数: 1>[输入]'HKLM' 'HKCU' 'HKU' 'HKCR' 2>[输入] 'SOFTWARE/Microsoft/Internet Explorer' 或者 '/SOFTWARE/Microsoft/Internet Explorer' 3>[输入]注册表键值名 /*返回值: True 成功 False 失败 /************************************************************************} procedure pro_JumpToKey(const str_param_Root:string; const str_param_KeyPath:string; const str_param_ValueName:string) ; var str_Root : string ; str_KeyPath : string ; str_ValueName : string ; int_Char_Index : Integer ; int_Char_Count : Integer ; hwnd_Win : HWND; hwnd_TreeView : HWND ; hwnd_ListView : HWND ; struct_ExecInfo : ShellExecuteInfo ; begin str_Root := '' ; str_KeyPath := '' ; str_ValueName := '' ; if str_param_Root = 'HKLM' then begin str_Root := 'HKEY_LOCAL_MACHINE' ; end else if str_param_Root = 'HKCU' then begin str_Root := 'HKEY_CURRENT_USER' ; end else if str_param_Root = 'HKU' then begin str_Root := 'HKEY_USERS' ; end else if str_param_Root = 'HKCR' then begin str_Root := 'HKEY_CLASSES_ROOT' ; end else begin Exit ; end; if Length(str_param_KeyPath) = 0 then begin Exit ; end else begin str_KeyPath := str_param_KeyPath ; if str_KeyPath[1] <> '/' then begin str_KeyPath := '/' + str_KeyPath ; end; end; // 组合注册表路径 ROOT/KEYPHT str_KeyPath := str_Root+str_KeyPath ; // 开始定位 // 1> 打开注册表编辑器 hwnd_Win := FindWindow(PChar('RegEdit_RegEdit'), nil); if hwnd_Win = 0 then begin FillChar(struct_ExecInfo, 60, #0); with struct_ExecInfo do begin cbSize := 60; fMask := SEE_MASK_NOCLOSEPROCESS; lpVerb := PChar('open'); lpFile := PChar('regedit.exe'); nShow := 1; end; ShellExecuteEx(@struct_ExecInfo); WaitForInputIdle(struct_ExecInfo.hProcess, 200); hwnd_Win := FindWindow(PChar('RegEdit_RegEdit'), nil) ; end; ShowWindow(hwnd_Win, SW_SHOWNORMAL) ; // 2> 模拟按键定位KEYPAT [TreeView] hwnd_TreeView := FindWindowEx(hwnd_Win, 0, PChar('SysTreeView32'), nil); SetForegroundWindow(hwnd_TreeView); int_Char_Index := 30; // 收拢 repeat SendMessage(hwnd_TreeView, WM_KEYDOWN, VK_LEFT, 0); Dec(int_Char_Index); until int_Char_Index = 0; Sleep(300); SendMessage(hwnd_TreeView, WM_KEYDOWN, VK_RIGHT, 0); Sleep(300); int_Char_Index := 1; int_Char_Count := Length(str_KeyPath); repeat if str_KeyPath[int_Char_Index] = '/' then begin SendMessage(hwnd_TreeView, WM_KEYDOWN, VK_RIGHT, 0); Sleep(300); end else SendMessage(hwnd_TreeView, WM_CHAR, Integer(str_KeyPath[int_Char_Index]), 0); int_Char_Index := int_Char_Index + 1; until int_Char_Index = int_Char_Count; // 3> 模拟按键定位Value [ListView] hwnd_ListView := FindWindowEx(hwnd_Win, 0, PChar('SysListView32'), nil); SetForegroundWindow(hwnd_ListView); if Length(str_param_ValueName) <> 0 then begin str_ValueName := str_param_ValueName ; SendMessage(hwnd_ListView, WM_KEYDOWN, VK_DOWN, 0); Sleep(300); // 移动到右侧定位 int_Char_Index := 1; int_Char_Count := Length(str_ValueName); repeat SendMessage(hwnd_ListView, WM_CHAR, Integer(str_ValueName[int_Char_Index]), 0); int_Char_Index := int_Char_Index + 1; until int_Char_Index = int_Char_Count ; end ; end;// End pro_JumpToKey() //delphi/6722