Create processes and list all processes

Source: Internet
Author: User
Startupinfo Si = {sizeof (SI )};
Process_information PI;
Char * szcommandline = "cmd ";
Si. dwflags = startf_useshowwindow;
Si. wshowwindow = true;
Bool Bret =: CreateProcess (
Null,
Szcommandline,
Null,
Null,
0,
Create_new_console,
Null,
Null,
& Si,
& PI );
If (BRET)
{
: Closehandle (PI. hprocess );
: Closehandle (PI. hthread );
Printf ("the new process ID is % d \ n", Pi. dwprocessid );
Printf ("the thread ID of the new thread is % d \ n", Pi. dwthreadid );
}

Int Index = 0;
Processentry32 pe32;
Pe32.dwsize = sizeof (pe32 );
Handle hprocesssnap =: createconlhelp32snapshot (th32cs_snapprocess, 0 );
If (hprocesssnap = invalid_handle_value)
{
Printf ("createconlhelp32snapshow error! ");
Return-1;
}
Bool bmore =: process32first (hprocesssnap, & pe32 );
//: Exitprocess (0 );
While (bmore)
{
Printf ("***************** % d *************** \ n ", ++ index );
Printf ("process name: % s \ n", pe32.szexefile );
Printf ("process ID: % d \ n", pe32.th32processid );
Printf ("thread Nums: % d \ n", pe32.cntthreads );

If (! Strcmp (pe32.szexefile, "qq.exe "))
{
//: Enumprocesses (
DWORD dexitcode;
Handle hprocess =: OpenProcess (process_all_access, false, pe32.th32processid );
: Getexitcodeprocess (hprocess, & dexitcode );
If (still_active = dexitcode)
{
Printf ("% s exist! \ N ", pe32.szexefile );
}
Else
{
Printf ("% s does not exist! \ N ", pe32.szexefile );
}
If (hprocess! = NULL)
{
Terminateprocess (hprocess, 0 );
Printf ("###### % s ended successfully! ######## \ N ", pe32.szexefile );
}
: Getexitcodeprocess (hprocess, & dexitcode );
If (still_active = dexitcode)
{
Printf ("% s exist! \ N ", pe32.szexefile );
}
Else
{
Printf ("% s does not exist! \ N ", pe32.szexefile );
}
: Closehandle (hprocess );

}
Printf ("basic priority of the Process Creation thread % d \ n", pe32.pcpriclassbase );
Bmore =: process32next (hprocesssnap, & pe32 );
}
: Closehandle (hprocesssnap );

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.