Delphi7写的服务不稳定? 我在D7环境下,安装测试服务,运行正常。脱离D7,就运行不正常了。怎么回事呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 仔细检查你的代码吧.大牛用D7或CB6写的服务程序, 运行几年都没有问题. 满足会D7,同时又会BCB6,同时又是大牛想来想去,只有妖哥了,哈哈 现在已经测试,找到症结:我用一个servicestart函数,启动后服务功能不完全执行,手动启动服务没有这个问题。代码如下 :能帮我看看怎么回事吗?function ServiceStart(const ServiceName: string; const Computer: PChar = nil): Boolean;{ 启动服务}var SCM, SCH: SC_Handle; P: PChar;begin Result := False; SCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS); if SCM <> 0 then begin SCH := OpenService(SCM, PChar(ServiceName), SERVICE_ALL_ACCESS); if SCH <> 0 then begin Result := StartService(SCH, 0, P); CloseServiceHandle(SCH); end; CloseServiceHandle(SCM); end;end; 现在发现好像是安装的有问题。手工安装是执行:cmd.exe /c service.exe/install 因为我的服务里面带有两个timer,需要启动。让程序安装服务,timer就是启动不起来。 function InstallService(SvcName, SvcDispName, SvcFullPath: string): integer;var hSCM, hService: SC_HANDLE; sInfo: string; P: PChar;begin result := 0; hSCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS); if hSCM = 0 then begin result := GetLastError; exit; end; try hService := CreateService(hSCM, PChar(SvcName), PChar(SvcDispName), SERVICE_ALL_ACCESS, //SERVICE_START OR SERVICE_QUERY_STATUS OR _DELETE, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, //SERVICE_DEMAND_START, //SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, PChar(SvcFullPath), nil, nil, nil, nil, nil); if hService = 0 then begin result := GetLastError; case result of ERROR_ACCESS_DENIED: sInfo := 'ERROR_ACCESS_DENIED'; ERROR_CIRCULAR_DEPENDENCY: sInfo := 'ERROR_CIRCULAR_DEPENDENCY'; ERROR_DUPLICATE_SERVICE_NAME: sInfo := 'ERROR_DUPLICATE_SERVICE_NAME'; ERROR_INVALID_HANDLE: sInfo := 'ERROR_INVALID_HANDLE'; ERROR_INVALID_NAME: sInfo := 'ERROR_INVALID_NAME'; ERROR_INVALID_PARAMETER: sInfo := 'ERROR_INVALID_PARAMETER'; ERROR_INVALID_SERVICE_ACCOUNT: sInfo := 'ERROR_INVALID_SERVICE_ACCOUNT'; ERROR_SERVICE_EXISTS: sInfo := 'ERROR_SERVICE_EXISTS'; end; end else begin P := nil; StartService(hService, 0, p); //启动服务 CloseServiceHandle(hService); end; finally CloseServiceHandle(hSCM); end;end;InstallService('服务名', '显示名', '服务路径'); 请问怎么在程序中启动批处理文件?我用winexec(pchar('cmd.exe /c a.exe/install '),sw_show);一直不成功。。 用绝对路径试一试,如:c:\windows\system32\cmd.exe ,c:\a.exe或用ShellExecute,在uses ShellAPI; winexec(pchar('c:\windows\system32\cmd.exe /c c:\a.exe /install'),sw_hide);依然不管事 winexec(pchar('c:\windows\system32\cmd.exe /c c:\a.exe /install'),sw_hide);管事了,哈哈。。刚才我试的时候少了空格,回上一贴时,加了空格,于是过了!谢谢楼上朋友!! 怎么CSDN空间进不了了? DBChart X轴显示问题?? 只能导出到txt一次? 请问怎样隐藏进程 Delphi中调试程序时,怎么连注释掉的语句也能运行? ApplyUpdates(0)提交服务器会报错 急!!如何将WORD文档挂到DELPHI中做成帮助文档!在线等待。。 dephi6的帮助好像没有dephi5的帮助好用,是不是这样? 各位朋友们好,能看一下我这个有关Dbrid变色方面的问题吗? Kingron(WinAPI) Will you help me? 书上两段源码的疑问 关于delphi的cxgrid的一些问题
大牛用D7或CB6写的服务程序, 运行几年都没有问题.
想来想去,只有妖哥了,哈哈
现在已经测试,找到症结:我用一个servicestart函数,启动后服务功能不完全执行,手动启动服务没有这个问题。
代码如下 :能帮我看看怎么回事吗?function ServiceStart(const ServiceName: string; const Computer: PChar = nil): Boolean;
{
启动服务
}
var
SCM, SCH: SC_Handle;
P: PChar;
begin
Result := False;
SCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if SCM <> 0 then
begin
SCH := OpenService(SCM, PChar(ServiceName), SERVICE_ALL_ACCESS);
if SCH <> 0 then
begin
Result := StartService(SCH, 0, P);
CloseServiceHandle(SCH);
end;
CloseServiceHandle(SCM);
end;
end;
因为我的服务里面带有两个timer,需要启动。让程序安装服务,timer就是启动不起来。
function InstallService(SvcName, SvcDispName, SvcFullPath: string): integer;
var
hSCM, hService: SC_HANDLE;
sInfo: string;
P: PChar;
begin
result := 0;
hSCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if hSCM = 0 then
begin
result := GetLastError;
exit;
end;
try
hService := CreateService(hSCM,
PChar(SvcName),
PChar(SvcDispName),
SERVICE_ALL_ACCESS, //SERVICE_START OR SERVICE_QUERY_STATUS OR _DELETE,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START, //SERVICE_DEMAND_START, //SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
PChar(SvcFullPath),
nil, nil, nil, nil, nil); if hService = 0 then
begin
result := GetLastError;
case result of
ERROR_ACCESS_DENIED: sInfo := 'ERROR_ACCESS_DENIED';
ERROR_CIRCULAR_DEPENDENCY: sInfo := 'ERROR_CIRCULAR_DEPENDENCY';
ERROR_DUPLICATE_SERVICE_NAME: sInfo := 'ERROR_DUPLICATE_SERVICE_NAME';
ERROR_INVALID_HANDLE: sInfo := 'ERROR_INVALID_HANDLE';
ERROR_INVALID_NAME: sInfo := 'ERROR_INVALID_NAME';
ERROR_INVALID_PARAMETER: sInfo := 'ERROR_INVALID_PARAMETER';
ERROR_INVALID_SERVICE_ACCOUNT: sInfo := 'ERROR_INVALID_SERVICE_ACCOUNT';
ERROR_SERVICE_EXISTS: sInfo := 'ERROR_SERVICE_EXISTS';
end;
end
else
begin
P := nil;
StartService(hService, 0, p); //启动服务
CloseServiceHandle(hService);
end;
finally
CloseServiceHandle(hSCM);
end;
end;
InstallService('服务名', '显示名', '服务路径');
一直不成功。。
用绝对路径试一试,如:c:\windows\system32\cmd.exe ,c:\a.exe或用ShellExecute,在uses ShellAPI;
winexec(pchar('c:\windows\system32\cmd.exe /c c:\a.exe /install'),sw_hide);依然不管事
谢谢楼上朋友!!