若何干闭除自己程序外的全部其他利用程序[VC/C++编程]
本文“若何干闭除自己程序外的全部其他利用程序[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
获得当前激活的进程:
1:包含头文件tlhelp32.h
2:.cpp以下:
ListView2->Items->Clear();
TListItem *mItem;
AnsiString ExeFile;
Pointer pt,pt2;
unsigned int s;
DWORD size,size2;
HANDLE snapshot;
PROCESSENTRY32 processinfo;
processinfo.dwSize = sizeof(processinfo);
snapshot =
CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (snapshot==NULL) return;
bool flag = Process32First (snapshot,&processinfo);
while (flag)
{
mItem=ListView2->Items->Add();
ExeFile=AnsiString(processinfo.szExeFile);
mItem->Caption=ExeFile;
mItem->SubItems->Add(IntToStr(int(processinfo.th32ParentProcessID)));
mItem->SubItems->Add(IntToHex(int(processinfo.th32ProcessID),8).UpperCase());
size=GetFileVersionInfoSize(ExeFile.c_str(),&size2);
pt=malloc(size);
GetFileVersionInfo(ExeFile.c_str(),NULL,size,pt);
if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\FileVersion",&pt2,&s))
mItem->SubItems->Add(PChar(pt2));
if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\CompanyName",&pt2,&s))
mItem->SubItems->Add(PChar(pt2));
if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\FileDescription",&pt2,&s))
mItem->SubItems->Add(PChar(pt2));
free(pt);
flag = Process32Next(snapshot,&processinfo);
}
要杀除一个进程,必须得到该进程的父线成ID(避免仅仅杀除子进程).
if (ListView2->SelCount==0)
{
MessageBox(Handle,"请首先挑选一个进程!","中止进程",MB_OK|MB_ICONWARNING);
return;
}
int pPid=StrToInt(ListView2->Selected->SubItems->Strings[0]);
HANDLE ps = OpenProcess(1,false,pPid);
if(ps&&TerminateProcess(ps,-9))
{
MessageBox(Handle,"成功中止进程!","中止进程",MB_OK|MB_ICONINFORMATION);
}
else
MessageBox(Handle,"中止进程失利!","中止进程",MB_OK|MB_ICONWARNING);
ViewProcess();
以上是“若何干闭除自己程序外的全部其他利用程序[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |