Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenstart.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Services 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: base/system/sc/start.c 00005 * PURPOSE: Start a service 00006 * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com> 00007 * 00008 */ 00009 00010 #include "sc.h" 00011 00012 BOOL Start(LPCTSTR ServiceName, LPCTSTR *ServiceArgs, INT ArgCount) 00013 { 00014 SC_HANDLE hSCManager = NULL; 00015 SC_HANDLE hSc = NULL; 00016 LPSERVICE_STATUS_PROCESS pServiceInfo = NULL; 00017 00018 #ifdef SCDBG 00019 LPCTSTR *TmpArgs = ServiceArgs; 00020 INT TmpCnt = ArgCount; 00021 _tprintf(_T("service to control - %s\n"), ServiceName); 00022 _tprintf(_T("Arguments:\n")); 00023 while (TmpCnt) 00024 { 00025 _tprintf(_T(" %s\n"), *TmpArgs); 00026 TmpArgs++; 00027 TmpCnt--; 00028 } 00029 _tprintf(_T("\n")); 00030 #endif /* SCDBG */ 00031 00032 hSCManager = OpenSCManager(NULL, 00033 NULL, 00034 SC_MANAGER_CONNECT); 00035 if (hSCManager == NULL) 00036 { 00037 ReportLastError(); 00038 return FALSE; 00039 } 00040 00041 hSc = OpenService(hSCManager, 00042 ServiceName, 00043 SERVICE_START | SERVICE_QUERY_STATUS); 00044 00045 if (hSc == NULL) 00046 goto fail; 00047 00048 if (!ArgCount) 00049 { 00050 ServiceArgs = NULL; 00051 } 00052 00053 if (! StartService(hSc, 00054 ArgCount, 00055 ServiceArgs)) 00056 { 00057 _tprintf(_T("[SC] StartService FAILED %lu:\n\n"), GetLastError()); 00058 goto fail; 00059 } 00060 00061 pServiceInfo = QueryService(ServiceName); 00062 if (pServiceInfo != NULL) 00063 { 00064 PrintService(ServiceName, 00065 pServiceInfo, 00066 TRUE); 00067 } 00068 00069 HeapFree(GetProcessHeap(), 0, pServiceInfo); 00070 CloseServiceHandle(hSc); 00071 CloseServiceHandle(hSCManager); 00072 00073 return TRUE; 00074 00075 fail: 00076 ReportLastError(); 00077 if (pServiceInfo) HeapFree(GetProcessHeap(), 0, pServiceInfo); 00078 if (hSc) CloseServiceHandle(hSc); 00079 if (hSCManager) CloseServiceHandle(hSCManager); 00080 return FALSE; 00081 00082 } Generated on Sun May 27 2012 04:17:03 for ReactOS by
1.7.6.1
|