2006-08-25 17:50:26 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2007-10-19 23:21:45 +00:00
|
|
|
* PROJECT: ReactOS net command
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/network/net/cmdStop.c
|
2007-10-19 23:21:45 +00:00
|
|
|
* PURPOSE:
|
2006-08-25 17:50:26 +00:00
|
|
|
*
|
2007-10-19 23:21:45 +00:00
|
|
|
* PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
|
2006-08-25 17:50:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "net.h"
|
|
|
|
|
2012-09-24 12:37:12 +00:00
|
|
|
INT cmdStop(INT argc, WCHAR **argv)
|
2006-08-25 17:50:26 +00:00
|
|
|
{
|
2012-09-24 12:37:12 +00:00
|
|
|
SC_HANDLE hManager = NULL;
|
|
|
|
SC_HANDLE hService = NULL;
|
|
|
|
SERVICE_STATUS ServiceStatus;
|
|
|
|
DWORD dwError = ERROR_SUCCESS;
|
|
|
|
INT nError = 0;
|
2014-06-10 21:35:39 +00:00
|
|
|
INT i;
|
2012-09-24 12:37:12 +00:00
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
{
|
2019-04-09 19:44:03 +00:00
|
|
|
PrintMessageString(4381);
|
|
|
|
ConPuts(StdOut, L"\n");
|
2018-12-24 09:20:44 +00:00
|
|
|
PrintNetMessage(MSG_STOP_SYNTAX);
|
2012-09-24 12:37:12 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-06-10 21:35:39 +00:00
|
|
|
for (i = 2; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (_wcsicmp(argv[i], L"/help") == 0)
|
|
|
|
{
|
2019-04-09 19:44:03 +00:00
|
|
|
PrintMessageString(4381);
|
|
|
|
ConPuts(StdOut, L"\n");
|
2018-12-24 09:20:44 +00:00
|
|
|
PrintNetMessage(MSG_STOP_SYNTAX);
|
|
|
|
PrintNetMessage(MSG_STOP_HELP);
|
2014-06-10 21:35:39 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-24 12:37:12 +00:00
|
|
|
hManager = OpenSCManagerW(NULL,
|
|
|
|
SERVICES_ACTIVE_DATABASE,
|
|
|
|
SC_MANAGER_ENUMERATE_SERVICE);
|
|
|
|
if (hManager == NULL)
|
|
|
|
{
|
|
|
|
dwError = GetLastError();
|
|
|
|
nError = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
hService = OpenServiceW(hManager,
|
|
|
|
argv[2],
|
|
|
|
SERVICE_STOP);
|
|
|
|
if (hService == NULL)
|
|
|
|
{
|
|
|
|
dwError = GetLastError();
|
|
|
|
nError = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus))
|
|
|
|
{
|
|
|
|
dwError = GetLastError();
|
|
|
|
nError = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (hService != NULL)
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
|
|
|
|
if (hManager != NULL)
|
|
|
|
CloseServiceHandle(hManager);
|
|
|
|
|
|
|
|
if (dwError != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
/* FIXME: Print proper error message */
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdErr, L"Error: %lu\n", dwError);
|
2012-09-24 12:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nError;
|
2006-08-25 17:50:26 +00:00
|
|
|
}
|