请问怎么判断文件是否已经被打开。或者可执行文件已经运行?

解决方案 »

  1.   

    uses Tlhelp32;var lppe: TProcessEntry32;
        Found : boolean;
        Hand,hProcess:THandle;
    begin
      Hand:=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
      lppe.dwSize:=SizeOf(TProcessEntry32);
      found:=Process32First(Hand,lppe);
      while Found do
      begin
       hProcess:=OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,False,lppe.th32ProcessID);
       if hProcess>0  then
         if lppe.szExeFile='QQ.exe' then
          begin
            ShowMessage('QQ.exe已经运行');
            exit;
          end;
         Found := Process32Next(Hand,lppe);
      end;
       ShowMessage('QQ.exe没有运行');
    end;
      

  2.   

    我以前一直靠自己设置一个boolean全局变量(例如isOpen)来实现,
    当启动程序时,利用form的create事件将它设置为false, 
    而你执行文件的open操作时将它设为true,
    当而执行文件的close操作时将它设为false
    这样你就可以利用isOpen来判断文件是否打开,
    如果有多个文件,则要设置多个boolean变量。