Я пытаюсь создать службу, которая будет запускаться при запуске системы, и запустить ее немедленно. Сервис должен запускать мой exe-файл. Функция GetLastError возвращает код ошибки 1053.
int main(void)
{
SC_HANDLE SC_manager_handle;
SC_HANDLE service_handle;
LPCTSTR binary_path = "C:\\Users\\User\\AppData\\file.exe";
LPCTSTR display_name = "ExampleService";
LPCTSTR service_name = "EXAMPLE_SERVICE";
SC_manager_handle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
puts("-----------------------");
if(SC_manager_handle == NULL)
puts("Open SM Manager: FAILED");
else
puts("SC Manager: SUCCESS");
service_handle = CreateService(SC_manager_handle, service_name, display_name, SERVICE_ALL_ACCESS ,SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, binary_path, NULL, NULL, NULL, NULL, NULL);
if(service_handle == NULL)
puts("Create Service: FAILED");
else
puts("Service Create: SUCCESS");
// running the exe file immediately
if(!StartService(service_handle, 0, NULL))
printf("Start Service: FAILED | ERROR: %d\n", GetLastError());
else
puts("Service Start: SUCCESS");
CloseServiceHandle(SC_manager_handle);
CloseServiceHandle(service_handle);
return 0;
}