1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS net command 4 * FILE: base/applications/network/net/cmdStop.c 5 * PURPOSE: 6 * 7 * PROGRAMMERS: Magnus Olsen (greatlord@reactos.org) 8 */ 9 10 #include "net.h" 11 12 INT cmdStop(INT argc, WCHAR **argv) 13 { 14 SC_HANDLE hManager = NULL; 15 SC_HANDLE hService = NULL; 16 SERVICE_STATUS ServiceStatus; 17 DWORD dwError = ERROR_SUCCESS; 18 INT nError = 0; 19 INT i; 20 21 if (argc != 3) 22 { 23 ConResPuts(StdOut, IDS_GENERIC_SYNTAX); 24 PrintNetMessage(MSG_STOP_SYNTAX); 25 return 1; 26 } 27 28 for (i = 2; i < argc; i++) 29 { 30 if (_wcsicmp(argv[i], L"/help") == 0) 31 { 32 ConResPuts(StdOut, IDS_GENERIC_SYNTAX); 33 PrintNetMessage(MSG_STOP_SYNTAX); 34 PrintNetMessage(MSG_STOP_HELP); 35 return 1; 36 } 37 } 38 39 hManager = OpenSCManagerW(NULL, 40 SERVICES_ACTIVE_DATABASE, 41 SC_MANAGER_ENUMERATE_SERVICE); 42 if (hManager == NULL) 43 { 44 dwError = GetLastError(); 45 nError = 1; 46 goto done; 47 } 48 49 hService = OpenServiceW(hManager, 50 argv[2], 51 SERVICE_STOP); 52 if (hService == NULL) 53 { 54 dwError = GetLastError(); 55 nError = 1; 56 goto done; 57 } 58 59 if (!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus)) 60 { 61 dwError = GetLastError(); 62 nError = 1; 63 goto done; 64 } 65 66 done: 67 if (hService != NULL) 68 CloseServiceHandle(hService); 69 70 if (hManager != NULL) 71 CloseServiceHandle(hManager); 72 73 if (dwError != ERROR_SUCCESS) 74 { 75 /* FIXME: Print proper error message */ 76 ConPrintf(StdErr, L"Error: %lu\n", dwError); 77 } 78 79 return nError; 80 } 81