[Delphi (Object Pascal)] Delphi打开注册表编辑器并自动定位 →→→→→进入此内容的聊天室

来自 , 2021-03-03, 写在 Delphi (Object Pascal), 查看 162 次.
URL http://www.code666.cn/view/8f91c9c2
  1. {************************************************************************/
  2. /*函数名:    pro_JumpToKey(const str_param_Root:string;
  3.                         const str_param_KeyPath:string;
  4.                         const str_param_ValueName:string) ;
  5. /*功能:         注册表定位
  6. /*参数:   1>[输入]'HKLM' 'HKCU' 'HKU' 'HKCR'
  7.           2>[输入] 'SOFTWARE/Microsoft/Internet Explorer' 或者
  8.                    '/SOFTWARE/Microsoft/Internet Explorer'
  9.           3>[输入]注册表键值名
  10. /*返回值:    True  成功
  11.           False 失败
  12. /************************************************************************}
  13. procedure pro_JumpToKey(const str_param_Root:string;
  14.                         const str_param_KeyPath:string;
  15.                         const str_param_ValueName:string) ;
  16. var
  17.   str_Root      : string ;
  18.   str_KeyPath   : string ;
  19.   str_ValueName : string ;
  20.   int_Char_Index : Integer ;
  21.   int_Char_Count : Integer ;
  22.   hwnd_Win : HWND;
  23.   hwnd_TreeView : HWND ;
  24.   hwnd_ListView : HWND ;
  25.   struct_ExecInfo : ShellExecuteInfo ;
  26. begin
  27.   str_Root      := '' ;
  28.   str_KeyPath   := '' ;
  29.   str_ValueName := '' ;
  30.   if str_param_Root = 'HKLM' then
  31.   begin
  32.     str_Root := 'HKEY_LOCAL_MACHINE' ;
  33.   end
  34.   else if str_param_Root = 'HKCU' then
  35.   begin
  36.     str_Root := 'HKEY_CURRENT_USER' ;
  37.   end
  38.   else if str_param_Root = 'HKU' then
  39.   begin
  40.     str_Root := 'HKEY_USERS' ;
  41.   end
  42.   else if str_param_Root = 'HKCR' then
  43.   begin
  44.     str_Root := 'HKEY_CLASSES_ROOT' ;
  45.   end
  46.   else
  47.   begin
  48.     Exit ;
  49.   end;
  50.   if Length(str_param_KeyPath) = 0 then
  51.   begin
  52.     Exit ;
  53.   end
  54.   else
  55.   begin
  56.     str_KeyPath := str_param_KeyPath ;
  57.     if str_KeyPath[1] <> '/' then
  58.     begin
  59.       str_KeyPath := '/' + str_KeyPath ;
  60.     end;
  61.   end;
  62.   // 组合注册表路径 ROOT/KEYPHT
  63.   str_KeyPath := str_Root+str_KeyPath ;
  64.   // 开始定位
  65.  
  66.   // 1> 打开注册表编辑器
  67.   hwnd_Win := FindWindow(PChar('RegEdit_RegEdit'), nil);
  68.   if hwnd_Win = 0 then
  69.   begin
  70.     FillChar(struct_ExecInfo, 60, #0);
  71.     with struct_ExecInfo do
  72.     begin
  73.       cbSize := 60;
  74.       fMask  := SEE_MASK_NOCLOSEPROCESS;
  75.       lpVerb := PChar('open');
  76.       lpFile := PChar('regedit.exe');
  77.       nShow  := 1;
  78.     end;
  79.     ShellExecuteEx(@struct_ExecInfo);
  80.     WaitForInputIdle(struct_ExecInfo.hProcess, 200);
  81.     hwnd_Win := FindWindow(PChar('RegEdit_RegEdit'), nil) ;
  82.   end;
  83.   ShowWindow(hwnd_Win, SW_SHOWNORMAL) ;
  84.   // 2> 模拟按键定位KEYPAT [TreeView]
  85.   hwnd_TreeView := FindWindowEx(hwnd_Win, 0, PChar('SysTreeView32'), nil);
  86.   SetForegroundWindow(hwnd_TreeView);
  87.   int_Char_Index := 30;  // 收拢
  88.   repeat
  89.     SendMessage(hwnd_TreeView, WM_KEYDOWN, VK_LEFT, 0);
  90.     Dec(int_Char_Index);
  91.   until int_Char_Index = 0;
  92.   Sleep(300);
  93.   SendMessage(hwnd_TreeView, WM_KEYDOWN, VK_RIGHT, 0);
  94.   Sleep(300);
  95.   int_Char_Index := 1;
  96.   int_Char_Count := Length(str_KeyPath);
  97.   repeat
  98.     if str_KeyPath[int_Char_Index] = '/' then
  99.     begin
  100.       SendMessage(hwnd_TreeView, WM_KEYDOWN, VK_RIGHT, 0);
  101.       Sleep(300);
  102.     end
  103.     else
  104.       SendMessage(hwnd_TreeView, WM_CHAR, Integer(str_KeyPath[int_Char_Index]), 0);
  105.     int_Char_Index := int_Char_Index + 1;
  106.   until int_Char_Index = int_Char_Count;
  107.   // 3> 模拟按键定位Value [ListView]
  108.   hwnd_ListView := FindWindowEx(hwnd_Win, 0, PChar('SysListView32'), nil);
  109.   SetForegroundWindow(hwnd_ListView);
  110.   if Length(str_param_ValueName) <> 0 then
  111.   begin
  112.     str_ValueName := str_param_ValueName ;
  113.     SendMessage(hwnd_ListView, WM_KEYDOWN, VK_DOWN, 0);
  114.     Sleep(300);
  115.     // 移动到右侧定位
  116.     int_Char_Index := 1;
  117.     int_Char_Count := Length(str_ValueName);
  118.     repeat
  119.       SendMessage(hwnd_ListView, WM_CHAR, Integer(str_ValueName[int_Char_Index]), 0);
  120.       int_Char_Index := int_Char_Index + 1;
  121.     until int_Char_Index = int_Char_Count ;
  122.   end ;
  123. end;// End pro_JumpToKey()
  124. //delphi/6722

回复 "Delphi打开注册表编辑器并自动定位"

这儿你可以回复上面这条便签

captcha