全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1653
推到 Plurk!
推到 Facebook!

探討:如何暫停正在執行的程式或避免自己的程式被暫停

答題得分者是:conundrum
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-05-18 11:24:05 IP:61.31.xxx.xxx 未訂閱
大家一起來探討一下。    1. 如何暫停正在執行的程式。( Pause Process )    使該 Process 被暫停了,亦可使暫停的程式繼續執行下去。    2. 如何避免自己的程式被暫停。    到底有幾種方法可以做到?    以下是透過 切換 Debug Mode方法,可以用來暫停別人的程式(Process) 藉以拋磚引玉。.......請大大們支持一下。    
====================================================================
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs
  ,TlHelp32, StdCtrls, Buttons,syncobjs;    Type
  TForm1 = class(TForm)
    edtFileName: TEdit;
    SpeedButton1: TSpeedButton;
    procedure Button1Click(Sender: TObject);
  private
    Ps_id: DWORD;
    Ps_handle: THANDLE;
    event: DEBUG_EVENT;
  public
  end;      TDebugThread = class(TThread)
  private
    event: DEBUG_EVENT;
  protected
    procedure Execute; override;
  end;    var
  Form1: TForm1;      evt: TEvent;
  pid: DWORD;    implementation    {$R *.DFM}    { TDebugThread }    procedure TDebugThread.Execute;
begin
 if DebugActiveProcess(pid) then
 begin
  evt := TEvent.Create(0, True, False, '');      while not Terminated do begin
    if WaitForDebugEvent(event, 1000) then
    begin
      while evt.WaitFor(10) <> wrSignaled do Sleep(100);
      if event.dwDebugEventCode = EXIT_PROCESS_DEBUG_EVENT then break;
      ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE);
    end;
  end;
 end;
end;    procedure TForm1.Button1Click(Sender: TObject);
var
    hSnapshoot: THandle;
    pe32: TProcessEntry32;
    DebugActiveProcessStop: function(dwProcessId: DWORD): boolean; cdecl;
    hLib: THandle;
    th: TDebugThread;
begin
  if SpeedButton1.Tag =0 then
  begin
    SpeedButton1.tag := 1;
    SpeedButton1.Caption := 'Release';        hSnapshoot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hSnapshoot = -1) then  Exit;        pe32.dwSize := SizeOf(TProcessEntry32);
    if (Process32First(hSnapshoot, pe32)) then
    repeat
      if (CompareText(PChar(ExtractFileName(pe32.szExeFile)),
                      PChar(edtFileName.Text)) = 0) or
         (CompareText(pe32.szExeFile,
                      PChar(PChar(edtFileName.Text))) = 0)  then begin
        ShowMessage('Got it!');
        ps_id := pe32.th32ProcessID;
        pid := ps_id;
        th := TDebugThread.Create(False);
        break;
      end;
    until not Process32Next(hSnapshoot, pe32);        CloseHandle (hSnapshoot);
  end else
  begin
    SpeedButton1.tag := 0;
    SpeedButton1.Caption := 'Suspend';
    evt.SetEvent;
  end;
end;    end.
==================================================================== 目前以想到抵制這種方法,可用透過自我檢查是否為 Debug 狀態。 另外,Game Maseter 也有暫停程式的功能, 不曉得其原理為何?若知道的請告知一下謝謝! 發表人 - wameng 於 2005/05/18 14:35:24
conundrum
尊榮會員


發表:893
回覆:1272
積分:643
註冊:2004-01-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-05-18 19:58:25 IP:218.175.xxx.xxx 未訂閱
http://www.sysinternals.com/files/Pstools.zip 利用這東西看看 有command可應用 pslist.exe >123.txt
系統時間:2024-05-08 8:43:05
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!