2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS SC utility
4 * FILE: subsys/system/sc/start.c
5 * PURPOSE: control ReactOS services
6 * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
8 * Ged Murphy 20/10/05 Created
14 BOOL
Start(LPCTSTR ServiceName
, LPCTSTR
*ServiceArgs
, INT ArgCount
)
17 SERVICE_STATUS_PROCESS ServiceStatus
;
21 _tprintf(_T("service to start - %s\n\n"), ServiceName
);
22 _tprintf(_T("Arguments :\n"));
25 printf("%s\n", *ServiceArgs
);
30 /* get a handle to the service requested for starting */
31 hSc
= OpenService(hSCManager
, ServiceName
, SERVICE_ALL_ACCESS
);
35 _tprintf(_T("openService failed\n"));
40 /* start the service opened */
41 if (! StartService(hSc
, ArgCount
, ServiceArgs
))
43 _tprintf(_T("StartService failed\n"));
48 if (! QueryServiceStatusEx(
50 SC_STATUS_PROCESS_INFO
,
51 (LPBYTE
)&ServiceStatus
,
52 sizeof(SERVICE_STATUS_PROCESS
),
55 _tprintf(_T("QueryServiceStatusEx 1 failed\n"));
61 while (ServiceStatus
.dwCurrentState
== SERVICE_START_PENDING
)
63 /* wait before checking status */
64 Sleep(ServiceStatus
.dwWaitHint
);
66 /* check status again */
67 if (! QueryServiceStatusEx(
69 SC_STATUS_PROCESS_INFO
,
70 (LPBYTE
)&ServiceStatus
,
71 sizeof(SERVICE_STATUS_PROCESS
),
74 _tprintf(_T("QueryServiceStatusEx 2 failed\n"));
80 CloseServiceHandle(hSc
);
82 if (ServiceStatus
.dwCurrentState
== SERVICE_RUNNING
)
84 _tprintf(_T("%s is running\n"), ServiceName
);
89 _tprintf(_T("Failed to start %s\n"), ServiceName
);
90 _tprintf(_T("Curent state: %lu\n"), ServiceStatus
.dwCurrentState
);
91 _tprintf(_T("Exit code: %lu\n"), ServiceStatus
.dwWin32ExitCode
);
92 _tprintf(_T("Service Specific exit code: %lu\n"),
93 ServiceStatus
.dwServiceSpecificExitCode
);
94 _tprintf(_T("Check point: %lu\n"), ServiceStatus
.dwCheckPoint
);
95 _tprintf(_T("Wait hint: %lu\n"), ServiceStatus
.dwWaitHint
);