#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "psapi.h"
void PrintProcessNameAndID( DWORD processID )
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR) );
}
}
// Print the process name and identifier.
_tprintf( TEXT("%s (PID: %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 );
}
список процессов-как его получить?
Может кто знает,как получить список процессов и как грохнуть процесс,зная его *.ехе-шник?:confused:
юзай поиск! тема поднималась не раз!
Цитата: umbrella
как получить список процессов:confused:
CreateToolhelp32Snapshot
А есть ли полный код? Вся прога от начала и до конца.
пример из мсдн:
Спасибо, но надо на ассме :)
Код:
Iam proc
local cb:DWORD
local p:PVOID
local dwMemAddr:DWORD
invoke GetCurrentProcessId
mov dword ptr myId,eax
and cb, 0
invoke ZwQuerySystemInformation, SystemProcessesAndThreadsInformation, addr p, 0, addr cb
.if cb!=0
invoke VirtualAlloc,0h,cb,MEM_COMMIT,PAGE_READWRITE
.if eax!=0
mov dwMemAddr,eax
mov p,eax
invoke ZwQuerySystemInformation,SystemProcessesAndThreadsInformation, p, cb, addr cb
.if eax == STATUS_SUCCESS
;invoke MessageBox,0h,$CTA0("ZwQuerySystemInformation Ok"),$CTA0("Ok"),MB_OK
mov edx,dword ptr myId
mov esi,p
assume esi:ptr SYSTEM_PROCESSES
again:
add esi,[esi].NextEntryDelta
mov eax,[esi].ProcessId
.if eax==edx
lea eax,[esi].ProcessName.Buffer
mov eax,[eax]
mov ebx,pSectionBaseAddress
assume ebx:ptr MY_SHARED_SECTION
mov [ebx].MyId,edx
lea edx,[ebx].MyName
push edx
invoke lstrcpyW,edx,eax
pop edx
push edx
invoke lstrlenW,edx
pop edx
add eax,2h
shl eax,1h
add eax,edx
mov [ebx].OffsetOfMyName,eax
assume ebx:nothing
.else
.if [esi].NextEntryDelta != 0h
jmp again
.endif
.endif
assume esi:nothing
.endif
.else
;invoke MessageBox,0h,$CTA0("VirtualAlloc Error"),$CTA0("Error"),MB_OK
.endif
invoke VirtualFree,dwMemAddr,cb,MEM_DECOMMIT
.if eax!=0
.else
;invoke MessageBox,0h,$CTA0("VirtualFree Error"),$CTA0("Error"),MB_OK
.endif
.endif
ret
Iam endp
local cb:DWORD
local p:PVOID
local dwMemAddr:DWORD
invoke GetCurrentProcessId
mov dword ptr myId,eax
and cb, 0
invoke ZwQuerySystemInformation, SystemProcessesAndThreadsInformation, addr p, 0, addr cb
.if cb!=0
invoke VirtualAlloc,0h,cb,MEM_COMMIT,PAGE_READWRITE
.if eax!=0
mov dwMemAddr,eax
mov p,eax
invoke ZwQuerySystemInformation,SystemProcessesAndThreadsInformation, p, cb, addr cb
.if eax == STATUS_SUCCESS
;invoke MessageBox,0h,$CTA0("ZwQuerySystemInformation Ok"),$CTA0("Ok"),MB_OK
mov edx,dword ptr myId
mov esi,p
assume esi:ptr SYSTEM_PROCESSES
again:
add esi,[esi].NextEntryDelta
mov eax,[esi].ProcessId
.if eax==edx
lea eax,[esi].ProcessName.Buffer
mov eax,[eax]
mov ebx,pSectionBaseAddress
assume ebx:ptr MY_SHARED_SECTION
mov [ebx].MyId,edx
lea edx,[ebx].MyName
push edx
invoke lstrcpyW,edx,eax
pop edx
push edx
invoke lstrlenW,edx
pop edx
add eax,2h
shl eax,1h
add eax,edx
mov [ebx].OffsetOfMyName,eax
assume ebx:nothing
.else
.if [esi].NextEntryDelta != 0h
jmp again
.endif
.endif
assume esi:nothing
.endif
.else
;invoke MessageBox,0h,$CTA0("VirtualAlloc Error"),$CTA0("Error"),MB_OK
.endif
invoke VirtualFree,dwMemAddr,cb,MEM_DECOMMIT
.if eax!=0
.else
;invoke MessageBox,0h,$CTA0("VirtualFree Error"),$CTA0("Error"),MB_OK
.endif
.endif
ret
Iam endp
Код:
#include <stdio.h>
#include <windows.h>
#include <tlhelp32.h>
void GetModuleList(DWORD th32ProcessID)
{
HANDLE h;
MODULEENTRY32 mdl;
h=CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,
th32ProcessID);
mdl.dwSize=sizeof(MODULEENTRY32);
Module32First(h,&mdl);
while(1)
{
printf("\tszExePath\t-\t%s\n",mdl.szExePath);
if (!Module32Next(h,&mdl)) break;
}
CloseHandle(h);
}
main()
{
HANDLE h;
PROCESSENTRY32 pe;
h=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);
pe.dwSize=sizeof(PROCESSENTRY32);
Process32First(h,&pe);
while(1)
{
printf("=>\t-\t%s\n",pe.szExeFile);
GetModuleList(pe.th32ProcessID);
if (!Process32Next(h,&pe)) break;
}
return 0;
}
#include <windows.h>
#include <tlhelp32.h>
void GetModuleList(DWORD th32ProcessID)
{
HANDLE h;
MODULEENTRY32 mdl;
h=CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,
th32ProcessID);
mdl.dwSize=sizeof(MODULEENTRY32);
Module32First(h,&mdl);
while(1)
{
printf("\tszExePath\t-\t%s\n",mdl.szExePath);
if (!Module32Next(h,&mdl)) break;
}
CloseHandle(h);
}
main()
{
HANDLE h;
PROCESSENTRY32 pe;
h=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);
pe.dwSize=sizeof(PROCESSENTRY32);
Process32First(h,&pe);
while(1)
{
printf("=>\t-\t%s\n",pe.szExeFile);
GetModuleList(pe.th32ProcessID);
if (!Process32Next(h,&pe)) break;
}
return 0;
}