unit server13;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,ComObj,Printers;type
TService13 = class(TService)
procedure ServiceExecute(Sender: TService);
private
{ Private }
public
function GetServiceController: TServiceController; override;
{ Public }
end;var
Service13: TService13;
implementation{$R *.DFM}procedure ServiceController(CtrlCode: DWord); stdcall;
begin
Service13.Controller(CtrlCode);
end;function TService13.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;procedure TService13.ServiceExecute(Sender: TService);
var
i : integer;
tmp : Integer;
begin
ShowMessage('Execute');
for i := 0 to Printer.Printers.Count - 1 do
begin
ShowMessage(Printer.Printers.Strings[i]);
end;
try
tmp := Printer.PrinterIndex;
//启动服务的时候,上面的代码抛出异常,而通过一般访问该代码一切正常,不知道问题出在什么地方,难道是服务程序的执行权限受到限制?服务程序应该是运行在系统级别的呀。
ShowMessage('Printer.PrinterIndex ='+IntToStr(tmp));
except
ShowMessage('Read PrinterIndex Error ='+IntToStr(GetLastError()));
end;while not Terminated do begin
ServiceThread.ProcessRequests(FALSE);
end;
end;end.//-------------------------------------------------------------
//server13.dfmobject Service13: TService13
OldCreateOrder = False
DisplayName = 'Servic13'
Interactive = True
StartType = stManual
OnExecute = ServiceExecute
Left = 192
Top = 107
Height = 480
Width = 696
end
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,ComObj,Printers;type
TService13 = class(TService)
procedure ServiceExecute(Sender: TService);
private
{ Private }
public
function GetServiceController: TServiceController; override;
{ Public }
end;var
Service13: TService13;
implementation{$R *.DFM}procedure ServiceController(CtrlCode: DWord); stdcall;
begin
Service13.Controller(CtrlCode);
end;function TService13.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;procedure TService13.ServiceExecute(Sender: TService);
var
i : integer;
tmp : Integer;
begin
ShowMessage('Execute');
for i := 0 to Printer.Printers.Count - 1 do
begin
ShowMessage(Printer.Printers.Strings[i]);
end;
try
tmp := Printer.PrinterIndex;
//启动服务的时候,上面的代码抛出异常,而通过一般访问该代码一切正常,不知道问题出在什么地方,难道是服务程序的执行权限受到限制?服务程序应该是运行在系统级别的呀。
ShowMessage('Printer.PrinterIndex ='+IntToStr(tmp));
except
ShowMessage('Read PrinterIndex Error ='+IntToStr(GetLastError()));
end;while not Terminated do begin
ServiceThread.ProcessRequests(FALSE);
end;
end;end.//-------------------------------------------------------------
//server13.dfmobject Service13: TService13
OldCreateOrder = False
DisplayName = 'Servic13'
Interactive = True
StartType = stManual
OnExecute = ServiceExecute
Left = 192
Top = 107
Height = 480
Width = 696
end
tmp := Printer.PrinterIndex;
//启动服务的时候,上面的代码抛出异常,而通过一般访问该代码一切正常,不知道问题出在什么地方,难道是服务程序的执行权限受到限制?服务程序应该是运行在系统级别的呀。
ShowMessage('Printer.PrinterIndex ='+IntToStr(tmp));
except
on e:Exception do
begin
ShowMessage('Error Desc:'+E.Message);//看一看你的到底报的是什么错,你就知道怎么办了
end;
end;
Help!!
Interactive = True
现在的问题是服务程序似乎有某些方面的限制,导致TPrinter对象出现异常。
我正在进一步试验(由于我以前也没做过,哈哈……),有结果马上相告!!
begin
Service13.Controller(CtrlCode);
end;function TService13.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
调用SERVICECONTROLLER时怎么没有参数?返回值又是哪里来的?
begin
Service13.Controller(CtrlCode);
end;function TService13.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
调用SERVICECONTROLLER时怎么没有参数?返回值又是哪里来的?
Printer 是个全局对象,在服务中使用会不会有问题呢?
但是这个普通应用程序中使用了很多TPrinter对象,OLE对象及DDE对象,在改写过程中对这些对象的使用出现了问题,无法绕过去。
即使不使用全局的TPrinter对象,而采用自己Create的方式,问题仍然存在。