C. Compile the Process Manager.

Source: Internet
Author: User

Example code:

# Include
# Include
# Include

Int main ()
{
PROCESSENTRY32 pe32;
Pe32.dwSize = sizeof (pe32 );

HANDLE hProcessSnap;
BOOL bMore;
Int count = 0;

HProcessSnap = createconlhelp32snapshot (TH32CS_SNAPPROCESS, 0 );

If (hProcessSnap = INVALID_HANDLE_VALUE)
{
Printf ("createconlhelp function call failed ");
Return 0;
}

BMore = Process32First (hProcessSnap, & pe32 );
Printf ("% 20 s % 10 s", "process name", "PID ");
Printf ("========================================== = ");
While (bMore)
{
Count ++;
Printf ("% 20 s % 10d", pe32.szExeFile, pe32.th32ProcessID );
BMore = Process32Next (hProcessSnap, & pe32 );
}
CloseHandle (hProcessSnap );
Return 0;
}


----------------------- EnumProcess Function

Example code:

# Include
# Include
# Include

# Pragma comment (lib, "psapi. lib ");

BOOL UpdateProcessPrivilege (HANDLE hProcess, LPCTSTR lpPrivilegeName = SE_DEBUG_NAME );

Void main ()
{
UpdateProcessPrivilege (GetCurrentProcess ());

DWORD processcount;
DWORD cbNeeded;
DWORD ProcessId [2, 1024];

EnumProcesses (ProcessId, sizeof (ProcessId), & cbNeeded );
Processcount = cbNeeded/sizeof (DWORD );

HMODULE hModule;
Char szPath [MAX_PATH];

For (DWORD I = 0; I {
// Open the process
HANDLE hProcess = OpenProcess (
PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE, ProcessId [I]);

Memset (szPath, 0, sizeof (szPath ));

If (hProcess)
{
EnumProcessModules (hProcess,
& HModule, sizeof (hModule), & cbNeeded );
GetModuleFileNameExA (hProcess,
HModule, szPath, sizeof (szPath ));
Printf ("ProcessID: % d (% s)", ProcessId [I], szPath );
}
Else
Printf ("Failed !!! ");

CloseHandle (hProcess );
}

Getchar (); // pause.
}

BOOL UpdateProcessPrivilege (HANDLE hProcess, LPCTSTR lpPrivilegeName)
{
HANDLE hToken;
Int iResult;
TOKEN_PRIVILEGES TokenPrivileges;

If (OpenProcessToken (hProcess, TOKEN_ALL_ACCESS, & hToken ))
{
LUID destLuid;
If (LookupPrivilegeValue (NULL, lpPrivilegeName, & destLuid ))
{
TokenPrivileges. PrivilegeCount = 1;
TokenPrivileges. Privileges [0]. Attributes = SE_PRIVILEGE_ENABLED;
TokenPrivileges. Privileges [0]. Luid = destLuid;

If (iResult = AdjustTokenPrivileges (hToken, FALSE,
& TokenPrivileges, 0, NULL, NULL )){
Return TRUE;
}
}
}
Return FALSE;
}

2. Process Shutdown

ExitProcess

TerminateProcess

3. enumeration process module

Sample Code:

Int Modlist (DWORD Pid)
{
HANDLE SnapP;
Struct tagMODULEENTRY32 modsnap;

DebugPrivilege (SE_DEBUG_NAME, TRUE );
SnapP = createconlhelp32snapshot (TH32CS_SNAPMODULE, Pid );
If (SnapP = (HANDLE)-1)
{
Sprintf (Temp, "Fail To createconlhelp32snapshot ");
SendMessage (Socket, Temp );
Return 1;
}
Modsnap. dwSize = sizeof (tagMODULEENTRY32 );
If (Module32First (SnapP, & modsnap ))
{
Sprintf (Temp, "The Process [% d] Module Infomation: ModuleName ModulePath", Pid );
Strcat (Temp ,"-------------------------------------------------------------------------------");
Printf ("% s", Temp );
Do
{
Sprintf (Temp, "%-21 s % s", modsnap. szModule, modsnap. szExePath );
Printf ("% s", Temp );
}
While (Module32Next (SnapP, & modsnap ));
Sprintf (Temp, "List Process Module Compeleted ");
}
Else
Sprintf (Temp, "Fail To Process32First ");
Printf ("% s", Temp );

DebugPrivilege (SE_DEBUG_NAME, FALSE );
CloseHandle (SnapP );

Return 0;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.