Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.04.09;
Скачать: CL | DM;

Вниз

WIN XP ПОЛНЫЙ ПУТЬ ПРОЦЕССА   Найти похожие ветки 

 
IGSE   (2006-01-19 13:36) [0]

вопрос

В списке процессов(Process32First,Process32Next) есть процесс NAME.EXE

КАК узнать путь этого NAME.EXE


 
AbrosimovA   (2006-01-19 13:50) [1]

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;


 
begin...end ©   (2006-01-19 13:51) [2]

OpenProcess + GetProcessImageFileName


 
IGSE   (2006-01-19 15:23) [3]

Всем СПАСИБО.
GetProcessImageFileName -> где находится?
и еще ?
имеем строку
C:\PROGRA~1\MICROS~2\OFFICE11\EXCEL.EXE
Можно ли получить действительный полный путь (без ~)


 
Игорь Шевченко ©   (2006-01-19 15:24) [4]


> Можно ли получить действительный полный путь (без ~)


GetLongPathName ?


 
IGSE   (2006-01-19 15:32) [5]

GetLongPathName
не могу найти


 
Rouse_ ©   (2006-01-19 16:07) [6]

 function GetLongPathNameA(lpszShortPath, lpszLongPath: PChar;
   cchBuffer: DWORD): DWORD; stdcall external kernel32;


 
IGSE   (2006-01-19 16:19) [7]

Спасибо


 
begin...end ©   (2006-01-19 16:23) [8]

> 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).


 
begin...end ©   (2006-01-19 16:27) [9]

К тому же, GetModuleFileNameEx даёт путь к файлу в более удобоваримом формате :)


 
Rouse_ ©   (2006-01-19 16:46) [10]


> К тому же, 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:51) [11]

> Rouse_ ©   (19.01.06 16:46) [10]

Это к чему? Я имел в виду, что GetModuleFileNameEx в этом отношении лучше , чем GetProcessImageFileName. Первая показывает в составе пути букву тома, тогда как вторая обозначает раздел как \Device\HarddiskVolumeX.


 
Rouse_ ©   (2006-01-19 16:53) [12]

Тьфу блин :) Точно :) Что-то я не внимателен стал :)



Страницы: 1 вся ветка

Текущий архив: 2006.04.09;
Скачать: CL | DM;

Наверх




Память: 0.5 MB
Время: 0.028 c
11-1124333832
DmiSb
2005-08-18 06:57
2006.04.09
Form.Show


2-1142956648
Nsk3D
2006-03-21 18:57
2006.04.09
Загрузка JPEG


2-1143091143
Nsk3D
2006-03-23 08:19
2006.04.09
Filter


2-1143135831
opoloxai
2006-03-23 20:43
2006.04.09
Как изменить дату создания файла?


1-1141311245
Andy BitOff
2006-03-02 17:54
2006.04.09
Обработка изображения. Метод.