From 82cd964e20a8fcc0ca946a0c6f89550bc9ed7d72 Mon Sep 17 00:00:00 2001 From: Ziliang Guo Date: Tue, 30 Apr 2013 02:57:30 +0000 Subject: [PATCH] [NET] Implementation of pause, continue, and help commands for net service application. Patch by theflash. Core-7131 #resolve svn path=/trunk/; revision=58894 --- .../applications/network/net/CMakeLists.txt | 3 ++ .../applications/network/net/cmdContinue.c | 51 +++++++++++++++++++ .../applications/network/net/cmdHelpMsg.c | 47 +++++++++++++++++ .../base/applications/network/net/cmdPause.c | 50 ++++++++++++++++++ reactos/base/applications/network/net/help.c | 2 +- reactos/base/applications/network/net/main.c | 7 +-- reactos/base/applications/network/net/net.h | 3 ++ 7 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 reactos/base/applications/network/net/cmdContinue.c create mode 100644 reactos/base/applications/network/net/cmdHelpMsg.c create mode 100644 reactos/base/applications/network/net/cmdPause.c diff --git a/reactos/base/applications/network/net/CMakeLists.txt b/reactos/base/applications/network/net/CMakeLists.txt index 279abd3d302..728cb077d02 100644 --- a/reactos/base/applications/network/net/CMakeLists.txt +++ b/reactos/base/applications/network/net/CMakeLists.txt @@ -5,6 +5,9 @@ list(APPEND SOURCE main.c cmdstart.c cmdStop.c + cmdHelpMsg.c + cmdPause.c + cmdContinue.c help.c) add_executable(net ${SOURCE}) diff --git a/reactos/base/applications/network/net/cmdContinue.c b/reactos/base/applications/network/net/cmdContinue.c new file mode 100644 index 00000000000..d8b69c82e6b --- /dev/null +++ b/reactos/base/applications/network/net/cmdContinue.c @@ -0,0 +1,51 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS net command + * FILE: cmdContinue.c + * PURPOSE: + * + * PROGRAMMERS: Aleksandar Andrejevic + */ + +#include "net.h" + +int cmdContinue(int argc, wchar_t *argv[]) +{ + int errorCode = 0; + SC_HANDLE hManager, hService; + SERVICE_STATUS status; + if(argc != 3) + { + puts("Usage: NET CONTINUE "); + return 1; + } + + hManager=OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ENUMERATE_SERVICE); + if(hManager == NULL) + { + printf("[OpenSCManager] Error: %d\n", errorCode = GetLastError()); + return errorCode; + } + + hService = OpenService(hManager, argv[2], SERVICE_PAUSE_CONTINUE); + + if(hService == NULL) + { + printf("[OpenService] Error: %d\n", errorCode=GetLastError()); + CloseServiceHandle(hManager); + return errorCode; + } + + if(!ControlService(hService, SERVICE_CONTROL_CONTINUE, &status)) + { + printf("[ControlService] Error: %d\n", errorCode=GetLastError()); + } + + CloseServiceHandle(hService); + CloseServiceHandle(hManager); + + return errorCode; +} + +/* EOF */ + diff --git a/reactos/base/applications/network/net/cmdHelpMsg.c b/reactos/base/applications/network/net/cmdHelpMsg.c new file mode 100644 index 00000000000..15a66c95724 --- /dev/null +++ b/reactos/base/applications/network/net/cmdHelpMsg.c @@ -0,0 +1,47 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS net command + * FILE: cmdHelpmsg.c + * PURPOSE: + * + * PROGRAMMERS: Aleksandar Andrejevic + */ + +#include "net.h" +#include "stdlib.h" + +int cmdHelpMsg(int argc, wchar_t *argv[]) +{ + wchar_t *endptr; + LPSTR lpBuffer; + if(argc<3) + { + puts("Usage: NET HELPMSG "); + return 1; + } + long errNum=wcstol(argv[2], &endptr, 10); + if(*endptr != 0) + { + puts("Usage: NET HELPMSG "); + return 1; + } + + /* Unicode printing is not supported in ReactOS yet */ + if(FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + errNum, + LANG_USER_DEFAULT, + (LPSTR)&lpBuffer, + 0, + NULL)) + { + printf("\n%s\n", lpBuffer); + LocalFree(lpBuffer); + } + else printf("Unrecognized error code: %ld\n", errNum); + + return 0; +} + +/* EOF */ + diff --git a/reactos/base/applications/network/net/cmdPause.c b/reactos/base/applications/network/net/cmdPause.c new file mode 100644 index 00000000000..2731a605ad7 --- /dev/null +++ b/reactos/base/applications/network/net/cmdPause.c @@ -0,0 +1,50 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS net command + * FILE: cmdPause.c + * PURPOSE: + * + * PROGRAMMERS: Aleksandar Andrejevic + */ + +#include "net.h" + +int cmdPause(int argc, wchar_t *argv[]) +{ + int errorCode=0; + SC_HANDLE hManager, hService; + SERVICE_STATUS status; + if(argc != 3) + { + puts("Usage: NET PAUSE "); + return 1; + } + + hManager = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ENUMERATE_SERVICE); + if(hManager == NULL) + { + printf("[OpenSCManager] Error: %d\n", errorCode=GetLastError()); + return errorCode; + } + + hService=OpenService(hManager, argv[2], SERVICE_PAUSE_CONTINUE); + if(hService == NULL) + { + printf("[OpenService] Error: %d\n", errorCode=GetLastError()); + CloseServiceHandle(hManager); + return errorCode; + } + + if(!ControlService(hService, SERVICE_CONTROL_PAUSE, &status)) + { + printf("[ControlService] Error: %d\n", errorCode=GetLastError()); + } + + CloseServiceHandle(hService); + CloseServiceHandle(hManager); + + return errorCode; +} + +/* EOF */ + diff --git a/reactos/base/applications/network/net/help.c b/reactos/base/applications/network/net/help.c index 4e33cc2b1bf..089f4a64f20 100644 --- a/reactos/base/applications/network/net/help.c +++ b/reactos/base/applications/network/net/help.c @@ -11,7 +11,7 @@ INT cmdHelp(INT argc, WCHAR **argv) { - if (argc > 3) + if (argc != 3) { return 0; } diff --git a/reactos/base/applications/network/net/main.c b/reactos/base/applications/network/net/main.c index 638a21f3d33..8f226967d2c 100644 --- a/reactos/base/applications/network/net/main.c +++ b/reactos/base/applications/network/net/main.c @@ -21,14 +21,15 @@ COMMAND cmds[] = {L"accounts", unimplemented}, {L"computer", unimplemented}, {L"config", unimplemented}, - {L"continue", unimplemented}, + {L"continue", cmdContinue}, {L"file", unimplemented}, {L"group", unimplemented}, {L"help", cmdHelp}, - {L"helpmsg", unimplemented}, + {L"helpmsg", cmdHelpMsg}, {L"localgroup", unimplemented}, {L"name", unimplemented}, {L"print", unimplemented}, + {L"pause", cmdPause}, {L"send", unimplemented}, {L"session", unimplemented}, {L"share", unimplemented}, @@ -39,7 +40,7 @@ COMMAND cmds[] = {L"use", unimplemented}, {L"user", unimplemented}, {L"view", unimplemented}, - + {NULL, NULL} }; int wmain(int argc, WCHAR **argv) diff --git a/reactos/base/applications/network/net/net.h b/reactos/base/applications/network/net/net.h index f7c11239520..660033f0be2 100644 --- a/reactos/base/applications/network/net/net.h +++ b/reactos/base/applications/network/net/net.h @@ -19,3 +19,6 @@ INT unimplemented(INT argc, WCHAR **argv); INT cmdHelp(INT argc, WCHAR **argv); INT cmdStart(INT argc, WCHAR **argv); INT cmdStop(INT argc, WCHAR **argv); +int cmdHelpMsg(int argc, wchar_t *argv[]); +int cmdPause(int argc, wchar_t *argv[]); +int cmdContinue(int argc, wchar_t *argv[]); -- 2.17.1