我现在想监测的是自己机器上的程序是否运行以及局域网中某台机器上的程序是否运行?比如说我机器有一个程序是A,我要在自己机器上能监测到它是否正在运行,而网络中的机器也能监测到它是否正在运行。
大侠们帮帮忙,很急啊!!!最好能给出相应的代码。小弟感激不尽

解决方案 »

  1.   

    这段代码是检测.一掉线马上就知道的,对你可能有帮助
    unit Link;
    interface
    function GateWay:string;
    procedure IfLink;implementation  uses  main,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,  StdCtrls, ExtCtrls,Registry,
      Grids;
    function GateWay:string;
         var
      Reg :TRegistry;
      MyStr : TStrings;
      buffer : array[0..1024] of byte;
      i:integer;
      info:TRegKeyInfo ;
      str:string;
    begin
      Result:='0';
      Reg :=TRegistry.Create;
      Mystr:=Tstringlist.Create;
      try
        Reg.RootKey :=HKEY_LOCAL_MACHINE;
        if Reg.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards',false) then
        begin
          if reg.GetKeyInfo(info) then
          begin      reg.GetKeyNames(mystr);
            str:='SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\'+Mystr.Strings[0];
            end;
        end;
      finally
       Reg.CloseKey;
        Mystr.Free;
         Reg.RootKey :=HKEY_LOCAL_MACHINE;
        if reg.OpenKey(str,false) then
          begin
             str:=reg.ReadString('ServiceName');
             end;
             Reg.CloseKey;
             Reg.RootKey :=HKEY_LOCAL_MACHINE;
         if reg.OpenKey('SYSTEM\CurrentControlSet\Services\'+str+'\Parameters\Tcpip\',false) then
            begin
               str:='';
              for i:= 1 to reg.ReadBinaryData('defaultGateway',buffer,sizeof(buffer)) do
               str:=str+chr(dword(buffer[i-1]));
               end;
                  if str=chr(0) then
                     begin
                       str:='';
                       for i:= 1 to reg.ReadBinaryData('DhcpDefaultGateway',buffer,sizeof(buffer)) do
                      str:=str+chr(dword(buffer[i-1]));
                       end;           Reg.CloseKey;
               reg.Free;
               if (str=char(0)) or (str='') then
               str:='66.218.71.88';
               result:=str;
      end;
    end;
    procedure IfLink;begin
     with mainForm do begin  ICMP.ReceiveTimeout:=10;
      try
      ICMP.Host := GateWay;
      ICMP.Ping; linklabel.caption:='正常';
     linkLabel.Font.Color:=clGreen;
      except
       linklabel.caption:='断开';
       mainform.linkLabel.Font.Color:=clred;
          end;
      end;
     end;end.
      

  2.   

    检测本机的可以用
    FindWindow
      

  3.   

    本机可以findwindow,但是网络那就不知道了
      

  4.   

    HPrevInst := FindWindow('TForm1',nil);
    if HPrevInst = 0 then showmessage('运行')
    ELSE showmessage('未运行');
    你得知道所要检测程序的窗体名