unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls,Tlhelp32;type
  TForm1 = class(TForm)
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  type
  Tth = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;
  end;
var
  Form1: TForm1;
  nHide: Integer; function FindProcessID(s:string):integer;
implementation{$R *.dfm}
function FindProcessID(s:string):integer;
var
found,find:boolean;
FSnapshotHandle:tHANDLE;
lppe:TProcessEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //CreateToolhelp32Snapshot函数得到进程快照
Find:=False;
lppe.dwSize := Sizeof(lppe); //初始化
found := Process32First(FSnapshotHandle, lppe); //Process32First 得到一个系统快照里第一个进程的信息
while found do
    begin
    if LowerCase(ExtractFileName(lppe.szExeFile))=LowerCase(s) then
      begin
      Result:=lppe.th32ProcessID; //找到进程返回ID
      find:=true;
      CloseHandle(FSnapshotHandle);
      exit;
      end;
      found := Process32Next(FSnapshotHandle, lppe);
    end;
  CloseHandle(FSnapshotHandle);
if find=False then
  Result:=0; //找不到进程返回0
end;{ Tth }procedure Tth.Execute;
var
  h,h2:Cardinal;
  ExitCode:Cardinal;
begin
while True do
begin
   if not FileExists('C:\Program Files\Thunder Network\Thunder2\Program\Thunder.exe') then
    begin
    ShowMessage('以下文件未找到:'+#13+#13+'C:\Program Files\Thunder Network\Thunder2\Program\Thunder.exe');
    Application.Terminate;
    end;  if FindProcessID('Thunder.exe') = 0 then
  begin
   if FindProcessID('ThunderService.exe')<>0 then
   begin
     h:= OpenProcess(EVENT_ALL_ACCESS,False,FindProcessID('ThunderService.exe'));
     GetExitCodeProcess(h,ExitCode);
     TerminateProcess(h,ExitCode);
   end
   else
   if FindProcessID('XLBugReport.exe')<>0 then
   begin
     h2:= OpenProcess(EVENT_ALL_ACCESS,False,FindProcessID('ThunderService.exe'));
     GetExitCodeProcess(h2,ExitCode);
     TerminateProcess(h2,ExitCode);
   end;   WinExec('C:\Program Files\Thunder Network\Thunder2\Program\Thunder.exe',SW_HIDE);
   nHide:= 0;
   Sleep(10000);
   end;
   if nHide=0 then
   begin
    keybd_event(VK_MENU, 0, 0, 0);
    keybd_event(ord('D'), 0, 0, 0);
    keybd_event(ord('D'), 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
    nHide:= 1;
   end;
   Sleep(5000);
end;end;procedure TForm1.FormShow(Sender: TObject);
var
  th: Tth;
begin
  inherited;
   th:= Tth.Create(False);
end;end.
为什么在FormShow中创建线程就出错:th:= Tth.Create(False);