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

Вниз

NtQuerySystemInformation - Как получить PID ?   Найти похожие ветки 

 
AlexRush ©   (2003-06-21 18:47) [0]

Как получить ID процесса по имени(в частности WINLOGON.EXE) ?


 
AlexRush ©   (2003-06-21 20:17) [1]

или хотя бы линк на тему....


 
ZZ ©   (2003-06-21 20:51) [2]

Типа сам себе отвечаешь или как? В смысле - почему именно NtQuerySystemInformation ? Особенно для winlogon"а...


 
AlexRush ©   (2003-06-21 20:54) [3]

Слушаю Ваши предложения...


 
ZZ ©   (2003-06-21 21:01) [4]

функция EnumProcesses и компания. Далее пример из MSDN

#include <windows.h>
#include <stdio.h>
#include "psapi.h"

void PrintProcessNameAndID( DWORD processID )
{
char szProcessName[MAX_PATH] = "unknown";

// Get a handle to the process.

HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );

// Get the process name.

if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;

if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
}
}

// Print the process name and identifier.

printf( "%s (Process ID: %u)\n", szProcessName, processID );

CloseHandle( hProcess );
}

void main( )
{
// Get the list of process identifiers.

DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;

if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return;

// Calculate how many process identifiers were returned.

cProcesses = cbNeeded / sizeof(DWORD);

// Print the name and process identifier for each process.

for ( i = 0; i < cProcesses; i++ )
( aProcesses[i] )
функция EnumProcesses и компания. Далее пример из MSDN

#include <windows.h>
#include <stdio.h>
#include "psapi.h"

void PrintProcessNameAndID( DWORD processID )
{
char szProcessName[MAX_PATH] = "unknown";

// Get a handle to the process.

HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );

// Get the process name.

if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;

if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
}
}

// Print the process name and identifier.

printf( "%s (Process ID: %u)\n", szProcessName, processID );

CloseHandle( hProcess );
}

void main( )
{
// Get the list of process identifiers.

DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;

if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return;

// Calculate how many process identifiers were returned.

cProcesses = cbNeeded / sizeof(DWORD);

// Print the name and process identifier for each process.

for ( i = 0; i < cProcesses; i++ )
PrintProcessNameAndID( aProcesses[i] );


 
неРуль   (2003-06-23 10:49) [5]

кхе, кхе, могет я что то и путаю (иногда бывает :), но ОпенПроцесс так просто процесс не откроет даже под админом

я делал так, может немного кривовато, но пашет

function GetFirstID(procname: string): longint;
var i: longint;
begin
@NtQuerySystemInformation:=GetProcAddress(GetModuleHandle("ntdll.dll"), "NtQuerySystemInformation");
if assigned(@NtQuerySystemInformation) then begin
GetMem(p, 30000);
proc:=p;
NtQuerySystemInformation(5, proc, 30000,i);
while true do begin
//в proc - все о процессе
if proc^.NextOffset=0 then break;
proc:=pointer(cardinal(proc)+proc^.NextOffset);
if proc.pModuleName=procname then begin
result:= proc.ProcessID;
break;
end;
end;
( p, 30000) кхе, кхе, могет я что то и путаю (иногда бывает :), но ОпенПроцесс так просто процесс не откроет даже под админом

я делал так, может немного кривовато, но пашет

function GetFirstID(procname: string): longint;
var i: longint;
begin
@NtQuerySystemInformation:=GetProcAddress(GetModuleHandle("ntdll.dll"), "NtQuerySystemInformation");
if assigned(@NtQuerySystemInformation) then begin
GetMem(p, 30000);
proc:=p;
NtQuerySystemInformation(5, proc, 30000,i);
while true do begin
//в proc - все о процессе
if proc^.NextOffset=0 then break;
proc:=pointer(cardinal(proc)+proc^.NextOffset);
if proc.pModuleName=procname then begin
result:= proc.ProcessID;
break;
end;
end;
FreeMem(p, 30000);
end;
end;

если что, могу расписать подробнее


 
ZZ ©   (2003-06-23 14:26) [6]

кхе, кхе, могет я что то и путаю (иногда бывает :), но ОпенПроцесс так просто процесс не откроет даже под админом
И часто бывает?


 
неРуль   (2003-06-23 14:53) [7]

ну не все, сервисы в основном без привилегий


 
AlexRush ©   (2003-06-25 15:26) [8]

неРуль (23.06.03 10:49)
>> если что, могу расписать подробнее >>
Распиши, коли не трудо... ;)


 
AlexRush ©   (2003-06-30 19:20) [9]

Удалено модератором
Примечание: Offtopic



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

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

Наверх




Память: 0.49 MB
Время: 0.025 c
1-1505
Злодей
2003-08-17 20:27
2003.09.01
Пуск


14-1630
Е-Моё имя
2003-08-13 09:52
2003.09.01
маразм крепчал


14-1653
Скорбящий
2003-08-13 20:05
2003.09.01
сабж


6-1541
BlackSun
2003-06-26 18:42
2003.09.01
RasGetEntryDialParams - не могу получить номер телефона


14-1636
Marconi
2003-08-12 07:54
2003.09.01
Цена делфи