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 PrintMessageString(4381); 24 ConPuts(StdOut, L"\n"); 25 PrintNetMessage(MSG_STOP_SYNTAX); 26 return 1; 27 } 28 29 for (i = 2; i < argc; i++) 30 { 31 if (_wcsicmp(argv[i], L"/help") == 0) 32 { 33 PrintMessageString(4381); 34 ConPuts(StdOut, L"\n"); 35 PrintNetMessage(MSG_STOP_SYNTAX); 36 PrintNetMessage(MSG_STOP_HELP); 37 return 1; 38 } 39 } 40 41 hManager = OpenSCManagerW(NULL, 42 SERVICES_ACTIVE_DATABASE, 43 SC_MANAGER_ENUMERATE_SERVICE); 44 if (hManager == NULL) 45 { 46 dwError = GetLastError(); 47 nError = 1; 48 goto done; 49 } 50 51 hService = OpenServiceW(hManager, 52 argv[2], 53 SERVICE_STOP); 54 if (hService == NULL) 55 { 56 dwError = GetLastError(); 57 nError = 1; 58 goto done; 59 } 60 61 if (!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus)) 62 { 63 dwError = GetLastError(); 64 nError = 1; 65 goto done; 66 } 67 68 done: 69 if (hService != NULL) 70 CloseServiceHandle(hService); 71 72 if (hManager != NULL) 73 CloseServiceHandle(hManager); 74 75 if (dwError != ERROR_SUCCESS) 76 { 77 /* FIXME: Print proper error message */ 78 ConPrintf(StdErr, L"Error: %lu\n", dwError); 79 } 80 81 return nError; 82 } 83