List of Qt scan processes and get process information

Source: Internet
Author: User

How to use:
Qmap<qstring,qint64> App_pid;
Getallapppidlist (APP_PID);

#include <tlhelp32.h>//for CreateToolhelp32Snapshot
#include <Psapi.h>   //For Getmodulefilenameex
#define FORMAT_PATH (PATH) path.replace (' \ \ ', '/'). ToLower ()
QString getpathbyprocessid (DWORD pid) {HANDLE hprocess=openprocess (process_all_access, FALSE, PID); if(!hprocess) {        //qmessagebox::warning (NULL, "Getpathbyprocessid", "unauthorized access to the process");        return "";    } WCHAR Filepath[max_path]; DWORD ret=Getmodulefilenameex (hprocess, NULL, FilePath, MAX_PATH); QString file=qstring::fromstdwstring (FilePath); //qmessagebox::warning (NULL, "Getpathbyprocessid ret=", Qstring::number (ret) + ":" +file);CloseHandle (hprocess); returnret==0?"": file;}voidUdpclient::getallapppidlist (qmap<qstring,qint64>&app_pid)    {PROCESSENTRY32 pe32; Pe32.dwsize=sizeof(PE32); HANDLE Hprocesssnap= CreateToolhelp32Snapshot (th32cs_snapprocess,0); if(Hprocesssnap = =Invalid_handle_value) {Warninglabel->settext ("CreateToolhelp32Snapshot call failed"); return ; } BOOL bmore= Process32First (hprocesssnap,&pe32);  while(bmore) {//printf ("Process name:%s\n", pe32.szexefile); //printf ("Process id:%u\n\n", pe32.th32processid);QString exename= (Qstring::fromutf16 (reinterpret_cast<ConstUnsigned Short*>(Pe32.szexefile))); QString ExePath=Getpathbyprocessid (PE32.TH32PROCESSID); ExePath=Format_path (ExePath); if(Exepath.isempty ()) {Warninglabel->settext ("Get Process"+ EXEName +"Path Failure"); }        Else{App_pid[exepath]=Pe32.th32processid; } bmore= Process32Next (hprocesssnap,&pe32); } closehandle (Hprocesssnap);}

List of Qt scan processes and get process information

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.