Copy Code code as follows:
#include <windows.h>
#include <iostream.h>
#include <tlhelp32.h>
#include <stdio.h>
int main (int argc, char* argv[])
{
Char exename[500];
printf ("[ENTER EXE FILE name]\t");
scanf ("%s", exename);
printf ("\n[you enter]\t%s\n", exename);
Sleep (3000);
Elevate the permissions of the current process so that it has permission to manipulate other processes
HANDLE Htoken;
Luid Sedebugnamevalue;
Token_privileges TKP;
if (! OpenProcessToken (GetCurrentProcess (),
Token_adjust_privileges | Token_query, &htoken)) {
WriteToLog ("OpenProcessToken error");
return 1;
}
if (! Lookupprivilegevalue (NULL, Se_debug_name, &sedebugnamevalue)) {
CloseHandle (Htoken);
WriteToLog ("Lookuprivilegevalue error");
return 1;
}
TKP. Privilegecount = 1;
TKP. Privileges[0]. Luid = Sedebugnamevalue;
TKP. Privileges[0]. Attributes = se_privilege_enabled;
if (! AdjustTokenPrivileges (Htoken, FALSE, &TKP, sizeof TKP, NULL, NULL)) {
CloseHandle (Htoken);
return 1;
}
Get the PID of the target process
DWORD pid;
HANDLE snapshot;
Snapshot=createtoolhelp32snapshot (th32cs_snapprocess,0);
struct TAGPROCESSENTRY32 processsnap;
Processsnap.dwsize=sizeof (TAGPROCESSENTRY32);
For (Process32First (SNAPSHOT,&PROCESSSNAP); Process32Next (SNAPSHOT,&PROCESSSNAP);) {
if (!stricmp (processsnap.szexefile,exename))
{
Pid=processsnap.th32processid;
Break
}
}
CloseHandle (snapshot);
////////////////////////////////////////
MODULEENTRY32 pe32;
Before you use this structure, set its size
pe32.dwsize = sizeof (PE32);
Take a snapshot of all the modules in the process
276 for the ID of a process
HANDLE Hprocesssnap = CreateToolhelp32Snapshot (th32cs_snapmodule,pid);
if (Hprocesssnap = = INVALID_HANDLE_VALUE)
{
Failed to establish snapshot
return-1;
printf ("[CreateToolhelp32Snapshot error]\n");
}
Iterate through the process snapshots, displaying information for each process in turn
BOOL bmore = Module32first (Hprocesssnap, &pe32);
while (bmore)
{
printf ("\n[dll name]\t%s\n", pe32.szmodule);
printf ("[DLL path]\t%s\n", Pe32.szexepath);
Bmore = Module32next (Hprocesssnap, &pe32);
}
Don't forget to clear off the snapshot object
CloseHandle (HPROCESSSNAP);
return 0;
}