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)