 |
program RemoteCmdLine;
uses Windows, madRemote;
function GetCmdLineThread(buffer: pchar) : dword; stdcall;
var cl : pchar;
begin
cl := GetCommandLine;
for result := 0 to MAX_PATH - 1 do begin
buffer[result] := cl[result];
if buffer[result] = #0 then
break;
end;
end;
function GetProcessCmdLine(processHandle: dword) : string;
var th, tid : dword;
entryPoint : pointer;
buffer : pointer;
params : pointer;
len : dword;
begin
entryPoint := CopyFunction(@GetCmdLineThread, processHandle, false, @buffer);
params := AllocMemEx(MAX_PATH, processHandle);
th := CreateRemoteThreadEx(processHandle, nil, 0, entryPoint, params, 0, tid);
WaitForSingleObject(th, INFINITE);
GetExitCodeThread(th, len);
SetLength(result, len);
ReadProcessMemory(processHandle, params, pointer(result), len, len);
CloseHandle(th);
FreeMemEx(params, processHandle);
FreeMemEx(buffer, processHandle);
end;
var wnd, pid, ph : dword;
begin
wnd := FindWindow('Shell_TrayWnd', '');
GetWindowThreadProcessID(wnd, @pid);
ph := OpenProcess(PROCESS_ALL_ACCESS, false, pid);
MessageBox(0, pchar('"' + GetProcessCmdLine(ph) + '"'),
'explorer''s command line...', MB_ICONINFORMATION);
CloseHandle(ph);
end.
|
|