“该文件”是你写的还是其他人写的?
“运行状态”具体指什么?
简单点可以用findwindow去找目标程序的窗口类、名,找到了就发送wm-close,找不到就运行;

解决方案 »

  1.   

    是的,你必须先要知道该窗体的标题。
    然后findwindows,跟他发送关闭消息
      

  2.   

    用createprocess, 并建立一个特殊的windowname, 用findwindow来
    找它, 如果没有, 就是运行完了. 用terminateprocess来关闭
      

  3.   

    给你一个使用Createprocess的函数,它可以运行外部程序或者命令,并 
    等待运行结束: 
     
    function WinExecAndWait32(FileName:String; Visibility : integer):integer; 
    var 
      zAppName:array[0..512] of char; 
      zCurDir:array[0..255] of char; 
      WorkDir:String; 
      StartupInfo:TStartupInfo; 
      ProcessInfo:TProcessInformation; 
    begin 
      StrPCopy(zAppName,FileName); 
      GetDir(0,WorkDir); 
      StrPCopy(zCurDir,WorkDir); 
      FillChar(StartupInfo,Sizeof(StartupInfo),#0); 
      StartupInfo.cb := Sizeof(StartupInfo); 
      StartupInfo.dwFlags := STARTF_USESHOWWINDOW; 
      StartupInfo.wShowWindow := Visibility; 
      if not CreateProcess(nil, 
        zAppName,                      { pointer to command line string } 
        nil,                           { pointer to process security attributes } 
        nil,                           { pointer to thread security attributes } 
        false,                         { handle inheritance flag } 
        CREATE_NEW_CONSOLE or          { creation flags } 
        NORMAL_PRIORITY_CLASS, 
        nil,                           { pointer to new environment block } 
        nil,                           { pointer to current directory name } 
        StartupInfo,                   { pointer to STARTUPINFO } 
        ProcessInfo) then Result := -1 { pointer to PROCESS_INF } 
      else begin 
        WaitforSingleObject(ProcessInfo.hProcess,INFINITE); 
        GetExitCodeProcess(ProcessInfo.hProcess,Result); 
      end; 
    end; 
      

  4.   

    给你一点简单的调用计算器的例子;
    var H:Hwnd;
    begin
      h:=Findwindow('SciCalc','计算器');
      if h=0 then
        winexec('Calc',SW_RESTORE) else
      begin
        // SetForegroundWindow(h);
        // showwindow(h,SW_RESTORE);这本来是把计算器提到前台的;
        sendmessage(h,wm_close,0,0); //改成关闭也没问题;
      end;
    //SendMessage(FindWindow('SciCalc','计算器'),WM_SETTEXT,0,Integer(PChar('这当然不是我做的计算器,不过我可以给它起一个我喜欢的名字')));
    end;
      

  5.   

    我知道 窗口的 标题是   BorlandSocketServer
           findwindow()  第一个 参数是什么  我不明白? 
      而 SciCalc  是  什么啊?
    为什么不能改啊?
      

  6.   

    findwindow函数的 第一个 参数 是做什么的
    第二个是  什么?
      

  7.   

    我要打开和 关闭的是  个服务器程序scktsrvr.exe          窗口的 标题是 
    BorlandSocktServer    第一个 参数是什么啊?
      

  8.   

    findwindow函数的第一个参数是窗口类名,用WinSight(Delphi自带的WS.exe) Spy++可以看到。用窗口类名查找窗口比用标题稳定,成功率更高。因为很多程序的标题是可变的而窗口类是固定的。
    窗口类:FindWindow('窗口类',nil);
    标题:FindWindow(nil,'标题');
      

  9.   

    可以举给例子说明 类名吗?比如为什么
    Calc 的类名 是SciCalc  >
    而我 如何  具体  获得 应用程序的类名啊?
    比如  我用delphi 编的  程序 类名 是什么
    还有   记事本的 类名是是什么啊?
    执行 应用程序好象 没有用路径 就可以找到这是为什么?
    如果这个 问题解决了  非常感谢 !
      

  10.   

    用delphi编的程序,它默认的类名:TForm1,TForm2...........
    如果缺工具,我可以给你一个查类名,caption属性,父窗口等等的好工具。
    发短信或EMAIL:[email protected]