天软金融分析.NET函数大全 > TSL函数 > 资源访问函数 > 进程相关函数 > 获取COM进程 > 实例展示

通过进程id实现对进程关闭    

  •   通过进程id对进程的关闭,比如,office中因为某些原因导致崩溃或者挂起时,就可以通过获取程ID将其关闭。
      以下就是通过进程ID关闭整个winword进程。
    //通过"test.docx"获得窗口句柄("test.docx"已打开)
    wnd:=SysGetWndOfCaption("test.docx");
    if not ifarray(wnd) then return 1;

    //通过窗口句柄获得winword进程的pid
    pid:=SysGetPidtidOfWnd(wnd[0]);
    if pid<=0 then return 1;

    //通过taskkill系统命令关闭winword进程
    execHandle := sysExec('C:\\Windows\\System32\\taskkill.exe',' /pid '$inttostr(pid)$' /f',0,0,returncode);
    return 1;