PDA

Ver la Versión Completa : Iniciar servicio de windows


jocey
19-09-2008, 19:05:55
Hola familia este codigo lo copie de una pagina y cuando lo compilo me da el siguiente error:

Constant expresion violate subrange bounds.

el codigo es el sgte, y el erros es en la linea que tengo subrayada en rojo.

function iniciarServicio (sMachine, sService: String) : Boolean;
var
schm,
schs: SC_Handle;
ss: TServiceStatus;
psTemp: PChar;
dwChkP: DWord;
begin
ss.dwCurrentState := -1;
schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);
if (schm>0) then
begin
schs := OpenService(schm, PChar(sService), SERVICE_START or
SERVICE_QUERY_STATUS);
if (schs>0) then
begin
psTemp := nil;
if (StartService(schs, 0, psTemp)) then
if (QueryServiceStatus(schs, ss)) then
while (SERVICE_RUNNING<>ss.dwCurrentState) do
begin
dwChkP := ss.dwCheckPoint;
Sleep(ss.dwWaitHint);
if (not QueryServiceStatus(schs, ss)) then
Break;
if (ss.dwCheckPoint < dwChkP) then
Break;
end;
CloseServiceHandle(schs);
end;
CloseServiceHandle(schm);
end;
Result := SERVICE_RUNNING=ss.dwCurrentState;
end;


cualquier ayuda sera bienvenida.
Gracias de antemano

DarkMan
19-09-2008, 21:29:13
...
ss.dwCurrentState := -1;
...




SS.dwCurrentState es de tipo cardinal. Según la ayuda de delphi, el tipo cardinal es:


Type Range Format
Cardinal 0..4294967295 unsigned 32-bit


Si te fijas en el rango que comprende el tipo Cardinal, el -1 no esta incluido. Lo que tu haces en esa línea es asignar -1 a una variable tipo Cardinal, lo que no está permitido.
Espero que esta respuesta te sirva.;)