Hi,
I have a service that I'm trying to start on windows vista
using this function:
function ServiceStart(const ServiceName: string): Boolean;
var
SCM, SCH: SC_Handle;
P: PChar;
begin
Result := False;
//SCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
SCM := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
if SCM <> 0 then
begin
//SCH := OpenService(SCM, PChar(ServiceName), SERVICE_ALL_ACCESS);
SCH := OpenService(SCM, PChar(ServiceName), SERVICE_START or
SERVICE_QUERY_STATUS);
if SCH <> 0 then begin
Result := StartService(SCH, 0, P);
CloseServiceHandle(SCH);
end;
CloseServiceHandle(SCM);
end;
end;
On windows XP it starts ok but on vista it says that it was
unable to start the service.
I'd try to modify the previliges of the OpenSCManager function
from SC_MANAGER_CONNECT to SC_MANAGER_ALL_ACCESS and the
previliges of OpenService function from SERVICE_START or
SERVICE_QUERY_STATUS
to SERVICE_ALL_ACCESS, but doesn't work.
What's wrong? How can I start a service on vista?
Thanks,
Carlos Matos