已知进行ID如果得到相应的句柄 ( 积分: 100 )

  • 主题发起人 主题发起人 sunjunfeng3
  • 开始时间 开始时间
S

sunjunfeng3

Unregistered / Unconfirmed
GUEST, unregistred user!
不能用OpenProecss这个函数不能在2K以后的版本中<br>我在各大论坛上都没有得到答案
 
不能用OpenProecss这个函数不能在2K以后的版本中<br>我在各大论坛上都没有得到答案
 
问题如何问的?瞌睡来了就睡觉吧!
 
已知进行ID如果得到相应的句柄 &nbsp;我在XP用OpenProecss函数不行,还有函数用可以吗
 
这是一段把DLL写入其他进程的代码(测试环境XP+DELPHI7)<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br> &nbsp;dllname:string;<br> &nbsp;progmanhandle:dword;<br> &nbsp;threadid:dword;<br> &nbsp;processid:dword;<br> &nbsp;funcp:pointer;<br> &nbsp;procid:pdword;<br> &nbsp;virp:pointer;<br> &nbsp;tmp:dword;<br> &nbsp;kerhandle:dword;<br>begin<br> &nbsp;////////////////////////////////////////////////////////<br> &nbsp;kerhandle:=GetModuleHandle(pchar('Kernel32.dll'));<br> &nbsp;if kerhandle&lt;&gt;0 then begin<br> &nbsp; &nbsp;funcp:=GetProcAddress(kerhandle,'LoadLibraryA');<br> &nbsp;end else exit;<br> &nbsp;////////////////////////////////////////////////////////<br> &nbsp;dllname:='g:/wpdll/wpdll.dll';<br> &nbsp;procid:=allocmem(4);<br> &nbsp;progmanhandle:=findwindow('Progman','Program Manager');<br> &nbsp;if progmanhandle&lt;&gt;0 then begin<br> &nbsp; &nbsp;threadid:=GetWindowThreadProcessId(progmanhandle,procid);<br> &nbsp; &nbsp;if threadid&lt;&gt;0 then begin<br> &nbsp; &nbsp; &nbsp;processid:=OpenProcess(PROCESS_CREATE_THREAD or PROCESS_VM_OPERATION or<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PROCESS_VM_WRITE,FALSE,procid^);<br> &nbsp; &nbsp; &nbsp;if processid&lt;&gt;0 then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;virp:=VirtualAllocEx(processid,nil,MAX_PATH,MEM_COMMIT,PAGE_READWRITE);<br> &nbsp; &nbsp; &nbsp; &nbsp;if virp&lt;&gt;nil then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if writeProcessMemory(processid,virp,pchar(dllname),MAX_PATH,tmp) then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CreateRemoteThread(processid,nil,0,funcp,virp,0,threadid);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;freemem(procid);<br>end;
 
function GetWindowID(hWnd: HWND): DWORD;<br>var<br> &nbsp;OwningProcess: DWORD;<br>begin<br> &nbsp;Result := GetWindowThreadProcessID(Handle, OwningProcess);<br>end;
 
不好意思,写反了。<br>type<br> &nbsp;tagWNDINFO = packed record<br> &nbsp; &nbsp;dwProcessId: DWORD;<br> &nbsp; &nbsp;hWnd: HWND;<br> &nbsp;end;<br> &nbsp;PWNDINFO = ^tagWNDINFO;<br><br>function GetProcessMainWnd(dwProcessId: DWORD): HWND;<br> &nbsp;function EnumFunc(const hWnd: Longword; lParam: Longint): BOOL; stdcall;<br> &nbsp;var<br> &nbsp; &nbsp;dwProcessId: DWORD;<br> &nbsp; &nbsp;pInfo: PWNDINFO;<br> &nbsp;begin<br> &nbsp; &nbsp;GetWindowThreadProcessId(hWnd, dwProcessId);<br> &nbsp; &nbsp;pInfo := PWNDINFO(lParam);<br> &nbsp; &nbsp;if dwProcessId = pInfo.dwProcessId then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;pInfo.hWnd := hWnd;<br> &nbsp; &nbsp; &nbsp;Result := False;<br> &nbsp; &nbsp;end<br> &nbsp; &nbsp;else Result := True;<br> &nbsp;end;<br>var<br> &nbsp;wi: tagWNDINFO;<br>begin<br> &nbsp;wi.dwProcessId := dwProcessId;<br> &nbsp;wi.hWnd := 0;<br> &nbsp;EnumWindows(@EnumFunc, Longint(@wi));<br> &nbsp;Result := wi.hWnd;<br>end;
 
多人接受答案了。
 
后退
顶部