如何使得在卸载时判断程序是否正在运行,并且结束它,然后进行删除?? 

解决方案 »

  1.   

    function FindProcess(AFileName: string): boolean;
    var
      hSnapshot: THandle;
      lppe: TProcessEntry32;
      Found: Boolean;
    begin
      Result :=False;
      hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
      lppe.dwSize := SizeOf(TProcessEntry32);
      Found := Process32First(hSnapshot, lppe);
    while Found do
    begin
        if ((UpperCase(ExtractFileName(lppe.szExeFile))=UpperCase(AFileName)) or (UpperCase(lppe.szExeFile )=UpperCase(AFileName))) then
        begin
          Result :=True;
        end;
        Found := Process32Next(hSnapshot, lppe);
    end;
    end;function KillTask(ExeFileName: string): integer;
    const
      PROCESS_TERMINATE=$0001;
    var
      ContinueLoop: BOOL;
      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; 
    end;
      

  2.   

      非常感谢您的回复,这是delphi代码是吧!我会好好看的。
    但是我想在NSIS里写代码进行检测。
    有相关的代码不?
      谢谢!