紧急求助-Windows 服务程序的制作 ( 积分: 100 )

  • 主题发起人 主题发起人 laobeli
  • 开始时间 开始时间
L

laobeli

Unregistered / Unconfirmed
GUEST, unregistred user!
程序功能,每五秒中更新服务的系统时间,为什么线程类中的输出文本文件能执行 FList.Add('123');
FList.SaveToFile('c:/aaaa.txt');而更新时间不能执行呢?
winexec( pchar('net time //192.168.1.18 /set /y'),SW_hide);
unit ServiceMain;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;

type
TSkyThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;

TSkyrityService = class(TService)
procedure ServiceContinue(Sender: TService; var Continued: Boolean);
procedure ServiceExecute(Sender: TService);
procedure ServicePause(Sender: TService; var Paused: Boolean);
procedure ServiceShutdown(Sender: TService);
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
private
{ Private declarations }
FSkyThread: TSkyThread;
FList:TStringList;
public
function GetServiceController: TServiceController; override;
procedure GT;
{ Public declarations }
end;


var
SkyrityService: TSkyrityService;

implementation

uses MainForm;

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
SkyrityService.Controller(CtrlCode);

end;

function TSkyrityService.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;

procedure TSkyrityService.ServiceContinue(Sender: TService;
var Continued: Boolean);
begin
while not Terminated do
begin
Sleep(10);
ServiceThread.ProcessRequests(False);
end;
end;

procedure TSkyrityService.ServiceExecute(Sender: TService);
begin
while not Terminated do
begin
Sleep(10);
ServiceThread.ProcessRequests(False);
end;
end;

procedure TSkyrityService.ServicePause(Sender: TService;
var Paused: Boolean);
begin
Paused := True;
end;

procedure TSkyrityService.ServiceShutdown(Sender: TService);
begin
//gbCanClose := true;
FrmMain.Free;
Status := csStopped;
ReportStatus();
end;

procedure TSkyrityService.ServiceStart(Sender: TService;
var Started: Boolean);
begin
Started := True;
flist:= tstringlist.Create;
FSkyThread:= TSkyThread.Create(false);
Svcmgr.Application.CreateForm(TFrmMain, FrmMain);
//gbCanClose := False;
//FrmMain.Hide;
end;

procedure TSkyrityService.ServiceStop(Sender: TService;
var Stopped: Boolean);
begin
Stopped := True;
//gbCanClose := True;
FrmMain.Free;
end;

procedure TSkyrityService.GT;
begin

FList.Add('123');
FList.SaveToFile('c:/aaaa.txt');
winexec( pchar('net time //192.168.1.18 /set /y'),SW_hide);
end;

{ Cservicetest }

procedure TSkyThread.Execute;
begin
inherited;
while not Terminated do
begin
SkyrityService.GT;
sleep(5000);
end;
end;
end.
 
[?][^][^][:(!][:(][:(][:D][:)]
 
默认服务是以System用户执行的,他没有登录你那个192.168.1.18
你让服务用指定用户执行,并且在代码中登录192.168.1.18
 
to 楼上的,192.168.1.18 是服务器的IP
服务程序是运行在客户端的, 或者你能不能详细描述下,我不太懂你的意思
 
你看看LogonUser,ImpersonateLoggedOnUser,WNetAddConnection2这三个API的
帮助吧,尤其是WNetAddConnection2。另外,你可以用NetRemoteTOD获取服务器时
 
这是解决问题的方法吗?方便告诉我你的QQ吗,想请教你
 

Similar threads

后退
顶部