Enter the program name to get the process ID and handle with the process's company name (using functions such as snapshots and Getpefilecompany and VERQUERYVALUEW)

Source: Internet
Author: User
Tags 04x

WORD getprocessidbyname (WCHAR *processname)
{


DWORD processId = 0;
HANDLE Hprocesssnap=createtoolhelp32snapshot (th32cs_snapprocess,0);
if (Hprocesssnap==invalid_handle_value)
{
return 0;
}


PROCESSENTRY32 pe32;
pe32.dwsize = sizeof (PROCESSENTRY32);


BOOL Bmore=process32first (HPROCESSSNAP,&PE32);
if (!bmore)
{
Goto __end;
}


Do
{
if (_wcsicmp (pe32.szexefile,processname) = = 0)
{
if (_wcsicmp (Pe32.szexefile,processname/*getprocessusername (PE32.TH32PROCESSID), L "SYSTEM" */) = = 0)
{
ProcessId = Pe32.th32processid;
Break
}


}
} while (Process32Next (HPROCESSSNAP,&PE32));


__end:


CloseHandle (HPROCESSSNAP);
return processId;
}

HANDLE ht = OpenProcess (PROCESS_ALL_ACCESS,FALSE,PROCESSID);

Application Company Name:
#pragma comment (lib, "Version.lib")

Process path name Child
void Getpefilecompany (wchar* file_path,wchar*&path) {
DWORD useless;
DWORD info_size = Getfileversioninfosizew (File_path, &useless);
if (Info_size > 0) {
BYTE *data_buffer = new byte[info_size*2/*+1*/];
ZeroMemory (data_buffer,info_size*2);
if (data_buffer!=null) {
if (getfileversioninfow (file_path, 0, info_size*2, Data_buffer)) {
void* data_ptr;
UINT Data_len;
if (Verqueryvaluew (Data_buffer, L "\\VarFileInfo\\Translation", &data_ptr, &data_len)) {
Const word* Ver_data = Reinterpret_cast<const word*> (data_ptr);
WCHAR fp_key[max_path]={0};
wsprintf (fp_key,l "\\StringFileInfo\\%04x%04x\\CompanyName",
Ver_data[0], ver_data[1]);
if (Verqueryvaluew (Data_buffer, Fp_key, &data_ptr, &data_len)) {
Path = new Wchar[data_len];
memcpy (path,data_ptr,data_len*2);
if (data_buffer! = NULL)
{
delete []data_buffer;
Data_buffer = NULL;
}
}
}
}
}
}
}
WCHAR *ppp = NULL;
Getpefilecompany (TP. GetBuffer (), PPP);
AfxMessageBox (PPP);
if (PPP! = NULL)
{
delete []PPP;
PPP = NULL;
}

http://blog.csdn.net/yjwffgip456/article/details/11079823

Enter the program name to get the process ID and handle with the process's company name (using functions such as snapshots and Getpefilecompany and VERQUERYVALUEW)

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.