关于Service Application的问题 ( 积分: 50 )

  • 主题发起人 主题发起人 gdtkd
  • 开始时间 开始时间
G

gdtkd

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个SERVICE APPLICATION程序A,是负责监控另外一个程序B是否运行,如果程序B关闭,程序A会自动重启程序B。<br>但是我没试时,程序B反复关闭多次后,发觉A自己会关闭(失效),程序A应该是当收到程序C的命令时才关闭,但程序C并没有运行。<br>各位大大能不能帮忙解决一下程序B为什么会自动关闭?
 
我做了一个SERVICE APPLICATION程序A,是负责监控另外一个程序B是否运行,如果程序B关闭,程序A会自动重启程序B。<br>但是我没试时,程序B反复关闭多次后,发觉A自己会关闭(失效),程序A应该是当收到程序C的命令时才关闭,但程序C并没有运行。<br>各位大大能不能帮忙解决一下程序B为什么会自动关闭?
 
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,<br> &nbsp;ExtCtrls, WinSvc;<br><br>type<br> &nbsp;TServerServiceName = class(TService)<br> &nbsp; &nbsp;Timer1: TTimer;<br> &nbsp; &nbsp;procedure Timer1Timer(Sender: TObject);<br> &nbsp;private<br> &nbsp;LogStr:String;<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;function GetServiceController: TServiceController; override;<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;ServerServiceName: TServerServiceName;<br> &nbsp; &nbsp;WndCaption: String;<br> &nbsp; &nbsp;FoundWnd: integer;<br>implementation<br>Uses PublibUnit;<br>{$R *.DFM}<br><br>procedure ServiceController(CtrlCode: DWord); stdcall;<br>begin<br> &nbsp;ServerServiceName.Controller(CtrlCode);<br>end;<br><br>function TServerServiceName.GetServiceController: TServiceController;<br>begin<br> &nbsp;Result := ServiceController;<br>end;<br><br>function EnumWndProc(hwnd: Thandle; Param: Cardinal): Bool; stdcall;<br>var<br> &nbsp;WndTitleText, WinModuleName: string;<br> &nbsp;WinInstance: THandle;<br>begin<br> &nbsp;Result := True;<br> &nbsp;SetLength(WndTitleText,100);<br> &nbsp;GetWindowText(hwnd,pchar(WndTitleText),Length(WndTitleText));<br> &nbsp;WndTitleText := Pchar(WndTitleText);<br> &nbsp;if pos(WndCaption,WndTitleText)&amp;gt;0 then<br> &nbsp;begin<br> &nbsp; &nbsp;FoundWnd := Hwnd;<br> &nbsp; &nbsp;Result := False; &nbsp;<br> &nbsp;end<br> &nbsp;else<br> &nbsp; &nbsp;FoundWnd:=0;<br>end;<br><br>procedure TServerServiceName.Timer1Timer(Sender: TObject);<br>var<br> &nbsp;ModuleName: string;<br>begin<br>Try<br> &nbsp;FoundWnd := 0;<br> &nbsp;WndCaption := 'ACCESSPassword';<br> &nbsp;EnumWindows(@EnumWndProc,0);<br> &nbsp;if FoundWnd=0 then<br> &nbsp; &nbsp;WinExec('E:/Access/Project1.exe',0);<br>Except on E : Exception do<br> &nbsp;Begin<br> &nbsp; &nbsp;LogStr := E.Message;<br> &nbsp; &nbsp;PublibUnit.Write_log(LogStr);<br> &nbsp; &nbsp;//Showmessage(E.Message);<br> &nbsp;End;<br>End;<br>end;<br><br>end.
 
真的没有会答吗,大富翁没有高手在吗?
 
后退
顶部