• delphi 打开和关闭外部exe


    一、打开外部exe

    1.use文件-SHELLAPI

    2.ShellExecute(handle,'open','E: est.exe','-s','',SW_SHOWNORMAL);

    二、关闭外部exe

    1.use文件-TLHelp32

    2.新建两个函数

    //查找正在运行的进程

    function TForm1.FindTask(ExeFileName: string): Boolean;
    const
    PROCESS_TERMINATE=$0001;
    var
    ContinueLoop: BOOL;
    FSnapshotHandle: THandle;
    FProcessEntry32: TProcessEntry32;
    begin
    result := False;
    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(ExtractFileName(ExeFileName))) or
    (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then
    begin
    Result := True;
    Break;
    end;
    ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
    end;
    CloseHandle(FSnapshotHandle);
    end;

    //关闭正在运行的进程

    function TForm1.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;
    CloseHandle(FSnapshotHandle);
    end;

    3.调用函数关闭进程(注意:ExeFileName是指exe的名称,不用带地址‘E:’)

    if FindTask('test.exe') then
      KillTask('test.exe');

  • 相关阅读:
    OSPF协议原理
    TCPDUMP抓包方法
    latex:画图
    FrankWolf算法
    Three20 Navigation 迁移到TTTableViewController一直显示加载中的解决办法
    ipa在iTunes中没有图标
    iPhone应用提交AppStore时Application failed codesign verification问题的解决
    XCode4.5 iOS6 SDK 提交AppStore Validate各种错误的解决
    1.forEach():遍历数组,并为每个元素调用传入的函数; 举例:
    CSS实现单行、多行文本溢出显示省略号(…)
  • 原文地址:https://www.cnblogs.com/linjincheng/p/12091764.html
Copyright © 2020-2023  润新知