Advertisement
Guest User

Untitled

a guest
May 8th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;
  7.  
  8. type
  9. TService12 = class(TService)
  10. procedure ServiceStart(Sender: TService; var Started: Boolean);
  11. procedure ServiceStop(Sender: TService; var Stopped: Boolean);
  12. procedure ServiceExecute(Sender: TService);
  13. private
  14. { Private declarations }
  15. public
  16. function GetServiceController: TServiceController; override;
  17. { Public declarations }
  18. end;
  19.  
  20. type
  21. TThread1 = class(TThread)
  22. private
  23. { Private declarations }
  24. protected
  25. procedure Execute; override;
  26. end;
  27.  
  28. var
  29. Service12: TService12;
  30. Thread1: TThread1;
  31.  
  32. implementation
  33.  
  34. {$R *.DFM}
  35.  
  36. procedure ServiceController(CtrlCode: DWord); stdcall;
  37. begin
  38. Service12.Controller(CtrlCode);
  39. end;
  40.  
  41. function TService12.GetServiceController: TServiceController;
  42. begin
  43. Result := ServiceController;
  44. end;
  45.  
  46. procedure write();
  47. var s:string;
  48. RC: Cardinal;
  49. f:textfile;
  50. begin
  51. try
  52. assignfile(f,'temp1.txt');
  53. rewrite(f);
  54. writeln(f,'123');
  55.  
  56. closefile(f);
  57. OutputDebugString('ADD');
  58. except
  59. OutputDebugString('ERROR');
  60. end;
  61. end;
  62.  
  63. procedure TThread1.Execute;
  64. begin
  65. while (true) do begin
  66. OutputDebugString('Start');
  67. write();
  68. OutputDebugString('END');
  69. Sleep(15000);
  70. end;
  71. end;
  72.  
  73.  
  74.  
  75. procedure TService12.ServiceStart(Sender: TService; var Started: Boolean);
  76. begin
  77. Thread1:=TThread1.Create(False);
  78. Thread1.Priority:=tpNormal;
  79.  
  80. Started := True;
  81.  
  82. end;
  83.  
  84.  
  85.  
  86. procedure TService12.ServiceStop(Sender: TService; var Stopped: Boolean);
  87. begin
  88. Stopped := True;
  89. end;
  90.  
  91. procedure TService12.ServiceExecute(Sender: TService);
  92. begin
  93. while not Terminated do begin
  94. ServiceThread.ProcessRequests(False);
  95. end;
  96. end;
  97.  
  98. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement