Форум: "WinAPI";
Текущий архив: 2002.12.23;
Скачать: [xml.tar.bz2];
ВнизКак по ID процесса определить FileName Найти похожие ветки
← →
dokkk (2002-11-09 23:07) [0]Как по ID процесса определить FileName того файла, который сей процесс запустил? (GetModuleFileName выдает какую-то хрень, наверное неправильно получаю манипулятор модуля)
← →
Ученик (2002-11-10 00:35) [1]Вариант от paul_shmakov ©, портированный в Delphi
function AdjustDebugPriviliges : Bool;
var
hTok : THandle;
tp : TTokenPrivileges;
begin
Result := False;
if OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, hTok) then try
if LookupPrivilegeValue(nil, "SeDebugPrivilege", tp.Privileges[0].Luid) then begin
tp.PrivilegeCount := 1;
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
Result := AdjustTokenPrivileges(hTok, False, tp, 0, PTokenPrivileges(nil)^, PDWord(nil)^)
end
finally
CloseHandle(hTok)
end
end;
function GetProcessCommandLine(dwProcessID : DWord; szBuffer : PChar; cbBuffer : DWORD) : Bool;
var
hProcess, hThread : THandle;
pGetCommandLine : Pointer;
pCommandLine : PChar;
dwRead, dwTID : DWord;
begin
Result := FALSE;
hProcess := OpenProcess(PROCESS_CREATE_THREAD or PROCESS_VM_READ or PROCESS_VM_OPERATION,
FALSE, dwProcessID);
if (hProcess <> 0) then try
pGetCommandLine := GetProcAddress(GetModuleHandle("kernel32.dll"), "GetCommandLineA");
if (pGetCommandLine <> nil) then begin
hThread := CreateRemoteThread(hProcess, NIL, 0, pGetCommandLine, nil, 0, dwTID);
if (hThread <> 0) then try
if WAIT_OBJECT_0 = WaitForSingleObject(hThread, 10000) then begin
if GetExitCodeThread(hThread, PDWord(@pCommandLine)^) then begin
if ReadProcessMemory(hProcess, pCommandLine, szBuffer, cbBuffer, dwRead) then begin
szBuffer[dwRead] := #0;
Result := TRUE
end
end
end
finally
CloseHandle(hThread)
end
end
finally
CloseHandle(hProcess)
end
end;
procedure TForm1.Button1Click(Sender: TObject);
var
szBuffer : array[0..MAX_PATH] of Char;
begin
AdjustDebugPriviliges;
if GetProcessCommandLine(StrToInt(Edit1.Text), szBuffer, MAX_PATH) then
ShowMessage(szBuffer)
end;
← →
Ученик (2002-11-10 00:38) [2]Еще вариант
function NTProcessExeName(hProcess : THandle) : string;
var
i : Integer;
cRequest, cModules : DWord;
hModules : array of DWORD;
szExeName : array[0..255] of Char;
begin
Result := "";
cRequest := 96; cModules := 0;
repeat
SetLength(hModules, cRequest div 4);
if not EnumProcessModules(hProcess, PDWord(Pointer(@hModules)^), cRequest, cModules) then
Break;
if cModules < cRequest then Break else cRequest := cRequest shl 1;
until False;
cModules := cModules div 4;
for i := 0 to cModules - 1 do begin
if GetModuleFileNameEx(hProcess, hModules[i], szExeName, 255) > 0 then begin
Result := StrPas(szExeName);
if CompareText(ExtractFileExt(Result), ".EXE") = 0 then Exit
end
end
end;
function ProcessExeName(ProcessID : THandle) : string;
var
hProcess,
hSnapshot : THandle;
ModuleEntry : TModuleEntry32;
begin
Result := "";
if IsWindowsNT then begin
hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or
PROCESS_VM_READ, False, ProcessID);
if hProcess <> 0 then try
Result := NTProcessExeName(hProcess)
finally
CloseHandle(hProcess)
end
end else begin
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPALL, ProcessID);
if hSnapshot > 0 then try
ModuleEntry.dwSize := SizeOf(ModuleEntry);
if Module32First(hSnapshot, ModuleEntry) then repeat
Result := StrPas(ModuleEntry.szExePath);
if CompareText(ExtractFileExt(Result), ".EXE") = 0 then
Exit
until not Module32Next(hSnapshot, ModuleEntry);
Result := ""
finally
CloseHandle(hSnapshot)
end
end
end;
← →
Ученик (2002-11-10 00:39) [3]>Ученик © (10.11.02 00:38)
uses
Psapi, TlHelp32;
← →
dokkk (2002-11-10 19:09) [4]Ok.
Сие верно и полезно
← →
Vitiy (2002-11-10 21:32) [5]Вдогонку...
А как по ID процесса определить :: сколько он кушает процессорных ресурсов (в процентах%) ?
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2002.12.23;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.008 c