Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencontrol.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/control.c 00005 * PURPOSE: Stops, pauses and resumes a service 00006 * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com> 00007 * 00008 */ 00009 00010 #include "sc.h" 00011 00012 BOOL 00013 Control(DWORD Control, 00014 LPCTSTR ServiceName, 00015 LPCTSTR *Args, 00016 INT ArgCount) 00017 { 00018 SC_HANDLE hSCManager = NULL; 00019 SC_HANDLE hSc = NULL; 00020 SERVICE_STATUS Status; 00021 DWORD dwDesiredAccess = 0; 00022 00023 #ifdef SCDBG 00024 LPCTSTR *TmpArgs = Args; 00025 INT TmpCnt = ArgCount; 00026 _tprintf(_T("service to control - %s\n"), ServiceName); 00027 _tprintf(_T("command - %lu\n"), Control); 00028 _tprintf(_T("Arguments:\n")); 00029 while (TmpCnt) 00030 { 00031 _tprintf(_T(" %s\n"), *TmpArgs); 00032 TmpArgs++; 00033 TmpCnt--; 00034 } 00035 _tprintf(_T("\n")); 00036 #endif /* SCDBG */ 00037 00038 switch (Control) 00039 { 00040 case SERVICE_CONTROL_STOP: 00041 dwDesiredAccess = SERVICE_STOP; 00042 break; 00043 00044 case SERVICE_CONTROL_PAUSE: 00045 dwDesiredAccess = SERVICE_PAUSE_CONTINUE; 00046 break; 00047 00048 case SERVICE_CONTROL_CONTINUE: 00049 dwDesiredAccess = SERVICE_PAUSE_CONTINUE; 00050 break; 00051 00052 case SERVICE_CONTROL_INTERROGATE: 00053 dwDesiredAccess = SERVICE_INTERROGATE; 00054 break; 00055 00056 case SERVICE_CONTROL_SHUTDOWN: 00057 dwDesiredAccess = 0; 00058 break; 00059 00060 } 00061 00062 hSCManager = OpenSCManager(NULL, 00063 NULL, 00064 SC_MANAGER_CONNECT); 00065 if (hSCManager != NULL) 00066 { 00067 hSc = OpenService(hSCManager, 00068 ServiceName, 00069 dwDesiredAccess); 00070 if (hSc != NULL) 00071 { 00072 if (ControlService(hSc, 00073 Control, 00074 &Status)) 00075 { 00076 SERVICE_STATUS_PROCESS StatusEx; 00077 00078 /* FIXME: lazy hack ;) */ 00079 CopyMemory(&StatusEx, &Status, sizeof(Status)); 00080 StatusEx.dwProcessId = 0; 00081 StatusEx.dwServiceFlags = 0; 00082 00083 PrintService(ServiceName, 00084 &StatusEx, 00085 FALSE); 00086 00087 CloseServiceHandle(hSc); 00088 CloseServiceHandle(hSCManager); 00089 00090 return TRUE; 00091 } 00092 } 00093 else 00094 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError()); 00095 } 00096 00097 ReportLastError(); 00098 if (hSc) CloseServiceHandle(hSc); 00099 if (hSCManager) CloseServiceHandle(hSCManager); 00100 return FALSE; 00101 } Generated on Sat May 26 2012 04:15:34 for ReactOS by
1.7.6.1
|