![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
WIN XP ПОЛНЫЙ ПУТЬ ПРОЦЕССА [D6]
IGSE © (2006-01-19 13:36:00)вопрос
В списке процессов(Process32First,Process32Next) есть процесс NAME.EXE
КАК узнать путь этого NAME.EXE
Rouse_ (2006-01-19 16:53:00) [1]Тьфу блин :) Точно :) Что-то я не внимателен стал :)
begin...end (2006-01-19 16:51:00) [2]> Rouse_ © (19.01.06 16:46) [10]
Это к чему? Я имел в виду, что GetModuleFileNameEx в этом отношении лучше , чем GetProcessImageFileName. Первая показывает в составе пути букву тома, тогда как вторая обозначает раздел как \Device\HarddiskVolumeX.
Rouse_ (2006-01-19 16:46:00) [3]
> К тому же, GetModuleFileNameEx даёт путь к файлу в более
> удобоваримом формате :)
Да? А мне казалось что вот так тоже вполне читабельно :)
var
ShortPath, LongPath: array[0..MAX_PATH - 1] of Char;
begin
if GetTempPath(MAX_PATH, @ShortPath[0]) > 0 then
if GetLongPathNameA(ShortPath, @LongPath[0], MAX_PATH) > 0 then
ShowMessage(String(LongPath));
К томуже нет ограничения по версии системы :)
begin...end (2006-01-19 16:27:00) [4]К тому же, GetModuleFileNameEx даёт путь к файлу в более удобоваримом формате :)
begin...end (2006-01-19 16:23:00) [5]> IGSE (19.01.06 15:23) [3]
> GetProcessImageFileName -> где находится?
В библиотеке psapi.dll, под именем GetProcessImageFileNameA (для ANSI) и GetProcessImageFileNameW (для Unicode):
function GetProcessImageFileName(
hProcess: Cardinal;
lpImageFileName: PChar;
nSize: Cardinal): Cardinal; stdcall; external 'psapi.dll' name 'GetProcessImageFileNameA';
Эта функция появилась, начиная с ХР. Если надо, чтобы работало и на предыдущих версиях (NT, 2000), используйте GetModuleFileNameEx (она тоже из psapi.dll).
IGSE (2006-01-19 16:19:00) [6]Спасибо
Rouse_ (2006-01-19 16:07:00) [7]
function GetLongPathNameA(lpszShortPath, lpszLongPath: PChar;
cchBuffer: DWORD): DWORD; stdcall external kernel32;
IGSE (2006-01-19 15:32:00) [8]GetLongPathName
не могу найти
Игорь Шевченко (2006-01-19 15:24:00) [9]
> Можно ли получить действительный полный путь (без ~)
GetLongPathName ?
IGSE (2006-01-19 15:23:00) [10]Всем СПАСИБО.
GetProcessImageFileName -> где находится?
и еще ?
имеем строку
C:\PROGRA~1\MICROS~2\OFFICE11\EXCEL.EXE
Можно ли получить действительный полный путь (без ~)
begin...end (2006-01-19 13:51:00) [11]OpenProcess + GetProcessImageFileName
AbrosimovA (2006-01-19 13:50:00) [12]
uses
PsAPI, TlHelp32, ImageHlp;
const
RsSystemIdleProcess = 'System Idle Process';
RsSystemProcess = 'System Process';
function IsWinXP: Boolean;
begin
Result := (Win32Platform = VER_PLATFORM_WIN32_NT) and
(Win32MajorVersion = 5) and (Win32MinorVersion = 1);
end;
function IsWin2k: Boolean;
begin
Result := (Win32MajorVersion >= 5) and
(Win32Platform = VER_PLATFORM_WIN32_NT);
end;
function IsWinNT4: Boolean;
begin
Result := Win32Platform = VER_PLATFORM_WIN32_NT;
Result := Result and (Win32MajorVersion = 4);
end;
function IsWin3X: Boolean;
begin
Result := Win32Platform = VER_PLATFORM_WIN32_NT;
Result := Result and (Win32MajorVersion = 3) and
((Win32MinorVersion = 1) or (Win32MinorVersion = 5) or
(Win32MinorVersion = 51));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RunningProcessesList(ListBox1.Items, true);
end;
function RunningProcessesList(const List: TStrings; FullPath: Boolean): Boolean;
function ProcessFileName(PID: DWORD): string;
var
Handle: THandle;
begin
Result := '';
Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
if Handle <> 0 then
try
SetLength(Result, MAX_PATH);
if FullPath then
begin
if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := '';
end
else
begin
if GetModuleBaseNameA(Handle, 0, PChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := '';
end;
finally
CloseHandle(Handle);
end;
end;
function BuildListTH: Boolean;
var
SnapProcHandle: THandle;
ProcEntry: TProcessEntry32;
NextProc: Boolean;
FileName: string;
begin
SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
Result := (SnapProcHandle <> INVALID_HANDLE_VALUE);
if Result then
try
ProcEntry.dwSize := SizeOf(ProcEntry);
NextProc := Process32First(SnapProcHandle, ProcEntry);
while NextProc do
begin
if ProcEntry.th32ProcessID = 0 then
begin
// PID 0 is always the "System Idle Process" but this name cannot be
// retrieved from the system and has to be fabricated.
FileName := RsSystemIdleProcess;
end
else
begin
if IsWin2k or IsWinXP then
begin
FileName := ProcessFileName(ProcEntry.th32ProcessID);
if FileName = '' then
FileName := ProcEntry.szExeFile;
end
else
begin
FileName := ProcEntry.szExeFile;
if not FullPath then
FileName := ExtractFileName(FileName);
end;
end;
List.AddObject(FileName, Pointer(ProcEntry.th32ProcessID));
NextProc := Process32Next(SnapProcHandle, ProcEntry);
end;
finally
CloseHandle(SnapProcHandle);
end;
end;
function BuildListPS: Boolean;
var
PIDs: array [0..1024] of DWORD;
Needed: DWORD;
I: Integer;
FileName: string;
begin
Result := EnumProcesses(@PIDs, SizeOf(PIDs), Needed);
if Result then
begin
for I := 0 to (Needed div SizeOf(DWORD)) - 1 do
begin
case PIDs[I] of
0:
// PID 0 is always the "System Idle Process" but this name cannot be
// retrieved from the system and has to be fabricated.
FileName := RsSystemIdleProcess;
2:
// On NT 4 PID 2 is the "System Process" but this name cannot be
// retrieved from the system and has to be fabricated.
if IsWinNT4 then
FileName := RsSystemProcess
else
FileName := ProcessFileName(PIDs[I]);
8:
// On Win2K PID 8 is the "System Process" but this name cannot be
// retrieved from the system and has to be fabricated.
if IsWin2k or IsWinXP then
FileName := RsSystemProcess
else
FileName := ProcessFileName(PIDs[I]);
else
FileName := ProcessFileName(PIDs[I]);
end;
if FileName <> '' then
List.AddObject(FileName, Pointer(PIDs[I]));
end;
end;
end;
begin
if IsWin3X or IsWinNT4 then
Result := BuildListPS
else
Result := BuildListTH;
end;