Форум: "WinAPI";
Текущий архив: 2003.09.01;
Скачать: [xml.tar.bz2];
Вниз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 вся ветка
Форум: "WinAPI";
Текущий архив: 2003.09.01;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.01 c