delphi5
win2000
아래 GetWindowFileNameNT 부분은 최용일님이 다른분에게 답변해주신거 보고 했는데 실행파일명만 가져오고 풀패스는 못가져오네요.
아시는 분 답변부탁합니다.
procedure TF_Login.Process32List(Slist: TStrings);
var
Process32: TProcessEntry32;
SHandle: THandle; // the handle of the Windows object
Next: BOOL;
begin
process32.dwSize := SizeOf(TProcessEntry32);
SHandle := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if Process32First(SHandle, process32) then
begin// 실행화일명과 process object 저장
Slist.AddObject(Process32.szExeFile, TObject(process32.th32ProcessID));
repeat
Next := Process32Next(SHandle, process32);
if Next then
begin
Slist.AddObject(Process32.szExeFile , TObject(process32.th32ProcessID));
end;
until not Next;
end;
CloseHandle(SHandle); // closes an open object handle
end;
function TF_Login.GetWindowFileNameNT(ProcessID: DWORD): string;
var
ProcessHandle: THandle;
FileName: array [0..Max_Path - 1] of char;
begin
Result := '';
ProcessHandle := OpenProcess(Process_Query_Information or Process_VM_Read, False, ProcessID);
if ProcessHandle <> 0 then
begin
if getmoduleBaseName(ProcessHandle, 0, FileName, SizeOf(FileName)) > 0 then
Result := FileName;
CloseHandle(ProcessHandle);
end;
end;
procedure TF_Login.Button1Click(Sender: TObject);
var
ProcId: DWORD;
i : integer;
begin
// 현재 실행중인 process를 검색
ListBox1.Items.Clear;
Process32List(ListBox1.Items);
for i := 0 to ListBox1.Items.Count - 1 do
begin
ProcId := DWORD(ListBox1.Items.Objects[i]);
Memo1.Lines.Add( GetWindowFileNameNT( ProcId ) );
end;
end;
아래와 같이 해보세요...
// GetModuleBaseName==>GetModuleFileNameEx
uses
...., Psapi;
function GetWindowFileNameNT(ProcessID: DWORD): string;
var
ProcessHandle: THandle;
FileName: array [0..Max_Path - 1] of char;
MH: THandle;
begin
Result := '';
ProcessHandle := OpenProcess(Process_Query_Information or Process_VM_Read, False, ProcessID);
if ProcessHandle <> 0 then
begin
if GetModuleFileNameEx(ProcessHandle, 0, FileName, SizeOf(FileName)) > 0 then
Result := FileName;
CloseHandle(ProcessHandle);
end;
end;
^^ 항상 즐코하세요...