ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

sc.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/sc.c
00005  * PURPOSE:     parse command line
00006  * COPYRIGHT:   Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
00007  *
00008  */
00009 
00010 #include "sc.h"
00011 
00012 SC_HANDLE hSCManager;
00013 
00014 VOID
00015 ReportLastError(VOID)
00016 {
00017     LPVOID lpMsgBuf;
00018     DWORD RetVal;
00019 
00020     DWORD ErrorCode = GetLastError();
00021     if (ErrorCode != ERROR_SUCCESS)
00022     {
00023         RetVal = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
00024                                FORMAT_MESSAGE_FROM_SYSTEM |
00025                                FORMAT_MESSAGE_IGNORE_INSERTS,
00026                                NULL,
00027                                ErrorCode,
00028                                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
00029                                (LPTSTR) &lpMsgBuf,
00030                                0,
00031                                NULL );
00032 
00033         if (RetVal != 0)
00034         {
00035             _tprintf(_T("%s"), (LPTSTR)lpMsgBuf);
00036             LocalFree(lpMsgBuf);
00037         }
00038     }
00039 }
00040 
00041 
00042 static INT
00043 ScControl(LPCTSTR Server,       // remote machine name
00044           LPCTSTR Command,      // sc command
00045           LPCTSTR *ServiceArgs, // any options
00046           DWORD ArgCount)       // argument counter
00047 {
00048     LPCTSTR ServiceName = NULL;
00049 
00050     if (Server)
00051     {
00052         _tprintf(_T("Remote service control is not yet implemented\n"));
00053         return 2;
00054     }
00055 
00056     if (!lstrcmpi(Command, _T("query")))
00057     {
00058         Query(ServiceArgs,
00059               ArgCount,
00060               FALSE);
00061     }
00062     else if (!lstrcmpi(Command, _T("queryex")))
00063     {
00064         Query(ServiceArgs,
00065               ArgCount,
00066               TRUE);
00067     }
00068     else if (!lstrcmpi(Command, _T("start")))
00069     {
00070         if (ArgCount > 0)
00071         {
00072             ServiceName = *ServiceArgs++;
00073             ArgCount--;
00074 
00075             Start(ServiceName,
00076                   ServiceArgs,
00077                   ArgCount);
00078         }
00079         else
00080             StartUsage();
00081     }
00082     else if (!lstrcmpi(Command, _T("pause")))
00083     {
00084         if (ArgCount > 0)
00085         {
00086             ServiceName = *ServiceArgs++;
00087             ArgCount--;
00088 
00089             Control(SERVICE_CONTROL_PAUSE,
00090                     ServiceName,
00091                     ServiceArgs,
00092                     ArgCount);
00093         }
00094         else
00095             PauseUsage();
00096     }
00097     else if (!lstrcmpi(Command, _T("interrogate")))
00098     {
00099         if (ArgCount > 0)
00100         {
00101             ServiceName = *ServiceArgs++;
00102             ArgCount--;
00103 
00104             Control(SERVICE_CONTROL_INTERROGATE,
00105                     ServiceName,
00106                     ServiceArgs,
00107                     ArgCount);
00108         }
00109         else
00110             InterrogateUsage();
00111     }
00112     else if (!lstrcmpi(Command, _T("stop")))
00113     {
00114         if (ArgCount > 0)
00115         {
00116             ServiceName = *ServiceArgs++;
00117             ArgCount--;
00118 
00119             Control(SERVICE_CONTROL_STOP,
00120                     ServiceName,
00121                     ServiceArgs,
00122                     ArgCount);
00123         }
00124         else
00125             StopUsage();
00126     }
00127     else if (!lstrcmpi(Command, _T("continue")))
00128     {
00129         if (ArgCount > 0)
00130         {
00131             ServiceName = *ServiceArgs++;
00132             ArgCount--;
00133 
00134             Control(SERVICE_CONTROL_CONTINUE,
00135                     ServiceName,
00136                     ServiceArgs,
00137                     ArgCount);
00138         }
00139         else
00140             ContinueUsage();
00141     }
00142     else if (!lstrcmpi(Command, _T("delete")))
00143     {
00144         if (ArgCount > 0)
00145         {
00146             ServiceName = *ServiceArgs++;
00147             ArgCount--;
00148 
00149             Delete(ServiceName);
00150         }
00151         else
00152             DeleteUsage();
00153     }
00154     else if (!lstrcmpi(Command, _T("create")))
00155     {
00156         Create(ServiceArgs, ArgCount);
00157     }
00158     else if (!lstrcmpi(Command, _T("control")))
00159     {
00160         INT CtlValue;
00161 
00162         if (ArgCount > 1)
00163         {
00164             ServiceName = *ServiceArgs++;
00165             ArgCount--;
00166 
00167             CtlValue = _ttoi(ServiceArgs[0]);
00168             ServiceArgs++;
00169             ArgCount--;
00170 
00171             if ((CtlValue >= 128) && (CtlValue <= 255))
00172                 Control(CtlValue,
00173                         ServiceName,
00174                         ServiceArgs,
00175                         ArgCount);
00176             else
00177                 ControlUsage();
00178         }
00179         else
00180             ControlUsage();
00181     }
00182     else
00183     {
00184         MainUsage();
00185     }
00186 
00187     return 0;
00188 }
00189 
00190 int _tmain(int argc, LPCTSTR argv[])
00191 {
00192     LPCTSTR Server = NULL;   // remote machine
00193     LPCTSTR Command = NULL;  // sc command
00194     LPCTSTR *Args = NULL;    // Any remaining args
00195 
00196     if (argc < 2)
00197     {
00198         MainUsage();
00199         return -1;
00200     }
00201 
00202     /* get server name */
00203     if ((argv[1][0] == '\\') && (argv[1][1] == '\\'))
00204     {
00205         if (argc < 3)
00206         {
00207             MainUsage();
00208             return -1;
00209         }
00210 
00211         Server = argv[1];
00212         Command = argv[2];
00213         if (argc > 3)
00214             Args = &argv[3];
00215 
00216         return ScControl(Server,
00217                          Command,
00218                          Args,
00219                          argc-3);
00220     }
00221     else
00222     {
00223         Command = argv[1];
00224         if (argc > 2)
00225             Args = &argv[2];
00226 
00227         return ScControl(Server,
00228                          Command,
00229                          Args,
00230                          argc-2);
00231     }
00232 }

Generated on Mon May 28 2012 04:17:28 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.