You are not logged in.
I've created a console program which is a HTTP server - OK
I've created a daemon program that uses the same classes from console program - OK
I can run the daemon using /console and it works - OK
However, if I try to /start the daemon, it "starts" but I got an error on log:
20201217 21340931 ! + ServDaemonCore.TDaemonService(026fb3e8).Stop
20201217 21340931 ! - 00.000.000
20201217 21340933 ! EXC EOleException 80040e4d ("Especificação de autorização inválida") [] at 4fc65e stack trace API 46ae31 404de8 77a171b4 77a03b36 4fc65e 407977 4e34b4 70b9ac 712bb1 713082 4d3c99 4d3601 760d1946 75f5fa29 779f75f4 779f75c4
It is in Portuguese... but debugging the original error is "Error 6 - The handle is invalid when trying to start services".
Running on Windows PRO; user is Admin; it's not antivirus.
Any tips?
Offline
Was the service at least installed?
The error here is indicative of its state, it is a GetLastError.
But the root cause is not this.
Use the debugger to find below when it was raised.
Offline
Yes, I can install without any problem.
If I use "/start", it seems that it's started (I can see on Windows Services that status was changed) doing nothing, as it was a fake start.
Debuggint I can see below that:
1. FHandle=0
2. backupError=5 — I'm not sure why 'OpenSCManager(''%'',''%'') for [%]' wasn't register on the log file, as I'm using "*", though.
constructor TServiceController.CreateOpenService(const TargetComputer,
DataBaseName, Name: String; DesiredAccess: DWORD);
var backupError: cardinal;
begin
inherited Create;
StringToUTF8(Name,FName);
FSCHandle := OpenSCManager(pointer(TargetComputer), pointer(DatabaseName),
GENERIC_READ);
if FSCHandle = 0 then begin
backupError := GetLastError;
ServiceLog.Add.Log(sllLastError,'OpenSCManager(''%'',''%'') for [%]',
[TargetComputer,DatabaseName,FName]);
SetLastError(backupError);
Exit;
end;
FHandle := OpenService(FSCHandle, pointer(Name), DesiredAccess);
if FHandle=0 then begin
backupError := GetLastError;
ServiceLog.Add.Log(sllLastError,'OpenService("%")',[Name]);
SetLastError(backupError);
end;
end;
After that, returning to the TSynDaemon.CommandLine() the function Show() is going to be executed:
cStart:
Show(ctrl.Start([]));
Than, the last error changes for "6", after execution of StartService():
function StartService(hService: SC_HANDLE; dwNumServiceArgs: DWORD;
lpServiceArgVectors: Pointer): BOOL; stdcall; external advapi32
name 'StartService'+{$ifdef UNICODE}'W'{$else}'A'{$endif};
Offline
Your OpenSCManager failed with ERROR_ACCESS_DENIED.
I think you must use "Run as Administrator".
Offline
So /install works but /start fails?
If this is the case, then the service may be half-installed.
IT happens when a service installation or execution was broken, due e.g. to the executable still running when uninstalling.
Unstall it, restart the PC, ensure it is actually uninstalled, then reinstall it.
Offline
Your OpenSCManager failed with ERROR_ACCESS_DENIED.
I think you must use "Run as Administrator".
I use from the beginning...
So /install works but /start fails?
If this is the case, then the service may be half-installed.
IT happens when a service installation or execution was broken, due e.g. to the executable still running when uninstalling.
Unstall it, restart the PC, ensure it is actually uninstalled, then reinstall it.
Yes, /install works but /start fails.
I did what you said and I got the same error.
On log, I have 2 Stop() calls when I tried to execute /install for the first time, after reboot.
Offline
Can you post a minimal working example?
Offline
Original code is complex (and I cannot post here). I will make an simple example without any access do DB just to know if this issue is something related to privilege to install—even though I'm using Admin, but the machine is not mine. It's part of a network with its own rules, antivirus, AD, etc.
If it works, it means that has something wrong in original code... however, it works perfectly on console mode.
Offline
I'm not asking you to post your code, just create a fresh dummy service that has no logic code and see if it starts on your system.
Offline
There may be some troubles about Windows service execution.
For instance, execution user rights, unmounted folder, and so on...
The service execution context is pretty specific, and don't match the app execution itself.
Try to move the service into another folder.
Offline
I don't use this feature on Windows, but I use Daemon on Linux.
I had problems, for obvious reasons, when using relative paths in the code (settings files), por example path of db.
The forked application could not find the files, because it was running in another context.
Offline