如何关闭除自己程序外的所有其他应用程序

时间:2010-04-27 16:15:17  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:NDLE 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();   ExeF...
  正文:获得当前激活的进程:
1:包含头文件tlhelp32.h
2:.cpp如下:

  ListView2->Items->Clear();
  TListItem *mItem;
  AnsiString ExeFile;
  Pointer pt,pt2;
  unsigned int s;
  Dword size,size2;
  HANDLE snaphotoshop/ target=_blank class=infotextkey>pshot;
  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 904E4FileVersion",&pt2,&s))
    mItem->SubItems->Add(PChar(pt2));
   if(VerQueryValue(pt,"StringFileInfo 904E4CompanyName",&pt2,&s))
    mItem->SubItems->Add(PChar(pt2));
   if(VerQueryValue(pt,"StringFileInfo 904E4FileDescription",&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();

"如何关闭除自己程序外的所有其他应用程序"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/VC/2010-04-27/13794.html


关键字:

关于《如何关闭除自己程序外的所有其他应用程序》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td