我试图跟随http://edn.embarcadero.com/article/28604重新启动Interbase。以下是一些代码:
program IBRestart;
{$APPTYPE CONSOLE}
uses
SysUtils, winsvc;
var
vManager, vService: SC_Handle;
vtmp: TServiceStatus;
begin
vManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if vManager > 0 then
begin
vService := OpenService(vManager, 'InterBaseGuardian', SERVICE_START or SERVICE_STOP);
if vService = 0 then // vService is always 0 here, why ?
CloseServiceHandle(vManager)
else
if ControlService(vService, SERVICE_CONTROL_STOP, vTmp) and
QueryServiceStatus(vService, vTmp) and
(vTmp.dwCurrentState = SERVICE_STOPPED) then
begin
WriteLn('Success');
end;
end;
end.我注意到该服务在服务对话框中被列为"InterBase 2009卫报gds_db“。我尝试过不同的变体作为OpenService的论据,但没有成功.有什么暗示吗?
编辑: net start将服务列表为InterBase 2009卫报gds_db和InterBase 2009 Server gds_db
RaiseLastOSError返回这两种情况:项目IBRestart.exe引发异常类EOSError,其中包含消息“System。代码: 1060。指定的服务不作为已安装的服务存在”。
因此,在上面的代码中,vService总是0。我甚至试图停止另一个类似主题的服务,它实际上是有效的。是否必须特殊处理字符串中的空格?我试图关闭IIS ,它返回了与Interbase相同的错误消息。
发布于 2010-01-04 10:14:04
这是我用于重新启动InterBase 2007的批处理文件,向您展示了一些机器上的服务名称在它们中有一个额外的空间()。
rem jpl: 20071015 - on some machines, the guardian service has an extra space
net stop "InterBase 2007 Guardian gds_db"
net stop "InterBase 2007 Guardian gds_db "
net stop "InterBase 2007 Server gds_db"
net start "InterBase 2007 Guardian gds_db"
net start "InterBase 2007 Guardian gds_db "
pause请注意,我两次停止并启动“卫报”;有时它在服务停止/启动超时期间内没有反应。我还专门停止了InterBase服务;它几乎不需要,但我曾经有过一次监护人服务停止,但InterBase服务没有停止。
-耶伦
发布于 2010-01-03 20:48:28
服务名称可能是错误的,或者您没有足够的权限(需要作为管理员启动)?很难说清楚到底出了什么问题。
请检查是否有任何调用发出错误信号(返回代码= 0),并在这种情况下调用RaiseLastOSError或SysErrorMessage(GetLastError)检查错误是什么。还要确保检查其他调用的错误。请用任何新的信息更新你的问题。
并将支票从> 0更改为<> 0。0表示错误,任何其他的成功。句柄可以是负数。并添加一些try..finally。并且不要忘记再次启动服务的代码:)此外,在调用ControlService之后,服务可能需要一段时间才能更改状态,因此QueryServiceStatus可能会返回SERVICE_STOP_PENDING一段时间,然后才真正停止。您的代码应该对此进行说明。有关示例,请参见这里。
program IBRestart;
{$APPTYPE CONSOLE}
uses
SysUtils, winsvc;
var
vManager, vService: SC_Handle;
vtmp: TServiceStatus;
begin
vManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if vManager <> 0 then
begin
try
vService := OpenService(vManager, 'InterBaseGuardian', SERVICE_START or SERVICE_STOP);
if vService = 0 then // vService is always 0 here, why ?
RaiseLastOSError; // This will give a hint why !
else
try
Win32Check(ControlService(vService, SERVICE_CONTROL_STOP, vTmp));
Win32Check(QueryServiceStatus(vService, vTmp));
if vTmp.dwCurrentState = SERVICE_STOPPED then // This might also be SERVICE_STOP_PENDING
WriteLn('Success')
else
WriteLn('Failure');
finally
CloseServiceHandle(vService);
end;
finally
CloseServiceHandle(vManager);
end;
end
else
RaiseLastOSError;
end.发布于 2010-01-03 22:27:56
守护者是一种在Ibserver.exe崩溃时重新启动的服务:它对于旧操作系统或作为应用程序运行ibserver非常有用。如果您将Ibserver用作服务,则可以在服务中直接管理它(在这种情况下,卫报是无用的)。
https://stackoverflow.com/questions/1996209
复制相似问题