比如我打开了一个文件文件c:\1.txt,这样notepad.exe进程肯定是有了,但我怎么样能杀掉这个进程呢
有个限制:  没有进程窗体,或者看不到程序运行的窗体,也不知道窗体名

解决方案 »

  1.   

    BOOL TerminateProcess(    HANDLE hProcess, // handle to the process 
        UINT uExitCode  // exit code for the process  
       );
      

  2.   

    function KillTask(ExeFileName:string):boolean;
    const 
      PROCESS_TERMINATE = $0001; 
    var
      ContinueLoop: BOOLean;
      FSnapshotHandle: THandle; 
      FProcessEntry32: TProcessEntry32;
    begin 
      Result := 0; 
      FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 
      FProcessEntry32.dwSize := SizeOf(FProcessEntry32); 
      ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);   while Integer(ContinueLoop) <> 0 do 
      begin 
        if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = 
          UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = 
          UpperCase(ExeFileName))) then 
          Result := Integer(TerminateProcess(
                            OpenProcess(PROCESS_TERMINATE, 
                                        BOOL(0), 
                                        FProcessEntry32.th32ProcessID), 
                                        0)); 
         ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); 
      end; 
      CloseHandle(FSnapshotHandle); 
    end;
      

  3.   

    感谢楼上,又学了一手。
    另:需要在uses里面加上Tlhelp32才OK