Author: ekohl
Date: Thu Jun 16 19:47:50 2016
New Revision: 71648
URL:
http://svn.reactos.org/svn/reactos?rev=71648&view=rev
Log:
[SC]
Add GetDisplayName command.
Added:
trunk/reactos/base/applications/sc/name.c (with props)
Modified:
trunk/reactos/base/applications/sc/CMakeLists.txt
trunk/reactos/base/applications/sc/sc.c
trunk/reactos/base/applications/sc/sc.h
trunk/reactos/base/applications/sc/usage.c
Modified: trunk/reactos/base/applications/sc/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/CMake…
==============================================================================
--- trunk/reactos/base/applications/sc/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/CMakeLists.txt [iso-8859-1] Thu Jun 16 19:47:50
2016
@@ -9,6 +9,7 @@
description.c
failure.c
misc.c
+ name.c
print.c
query.c
sc.c
Added: trunk/reactos/base/applications/sc/name.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/name.…
==============================================================================
--- trunk/reactos/base/applications/sc/name.c (added)
+++ trunk/reactos/base/applications/sc/name.c [iso-8859-1] Thu Jun 16 19:47:50 2016
@@ -0,0 +1,75 @@
+/*
+ * PROJECT: ReactOS Services
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: base/applications/sc/name.c
+ * PURPOSE:
+ * COPYRIGHT: Copyright 2016 Eric Kohl
+ *
+ */
+
+#include "sc.h"
+
+BOOL GetDisplayName(LPCTSTR ServiceName)
+{
+ SC_HANDLE hManager = NULL;
+ BOOL bResult = TRUE;
+ DWORD BufferSize = 0;
+ LPTSTR pBuffer = NULL;
+
+ hManager = OpenSCManager(NULL,
+ NULL,
+ SC_MANAGER_CONNECT);
+ if (hManager == NULL)
+ {
+ _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
+ bResult = FALSE;
+ goto done;
+ }
+
+ if (!GetServiceDisplayName(hManager,
+ ServiceName,
+ NULL,
+ &BufferSize))
+ {
+ if (BufferSize == 0)
+ {
+ _tprintf(_T("[SC] GetServiceDisplayName FAILED %lu:\n\n"),
GetLastError());
+ bResult = FALSE;
+ goto done;
+ }
+ }
+
+ pBuffer = HeapAlloc(GetProcessHeap(), 0, (BufferSize + 1) * sizeof(TCHAR));
+ if (pBuffer == NULL)
+ {
+ SetLastError(ERROR_OUTOFMEMORY);
+ _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
+ bResult = FALSE;
+ goto done;
+ }
+
+ BufferSize++;
+ if (!GetServiceDisplayName(hManager,
+ ServiceName,
+ pBuffer,
+ &BufferSize))
+ {
+ _tprintf(_T("[SC] GetServiceDisplayName FAILED %lu:\n\n"),
GetLastError());
+ bResult = FALSE;
+ goto done;
+ }
+
+ _tprintf(_T("[SC] GetServiceDisplayName SUCCESS Name = %s\n"), pBuffer);
+
+done:
+ if (bResult == FALSE)
+ ReportLastError();
+
+ if (pBuffer != NULL)
+ HeapFree(GetProcessHeap(), 0, pBuffer);
+
+ if (hManager)
+ CloseServiceHandle(hManager);
+
+ return bResult;
+}
Propchange: trunk/reactos/base/applications/sc/name.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/base/applications/sc/sc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/sc.c?…
==============================================================================
--- trunk/reactos/base/applications/sc/sc.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/sc.c [iso-8859-1] Thu Jun 16 19:47:50 2016
@@ -272,6 +272,18 @@
{
SetFailure(ServiceArgs, ArgCount);
}
+ else if (!lstrcmpi(Command, _T("GetDisplayName")))
+ {
+ if (ArgCount > 0)
+ {
+ ServiceName = *ServiceArgs++;
+ ArgCount--;
+
+ GetDisplayName(ServiceName);
+ }
+ else
+ GetDisplayNameUsage();
+ }
else
{
MainUsage();
Modified: trunk/reactos/base/applications/sc/sc.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/sc.h?…
==============================================================================
--- trunk/reactos/base/applications/sc/sc.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/sc.h [iso-8859-1] Thu Jun 16 19:47:50 2016
@@ -45,6 +45,7 @@
BOOL SetDescription(LPCTSTR ServiceName, LPCTSTR Description);
BOOL QueryFailure(LPCTSTR ServiceName);
BOOL SetFailure(LPCTSTR *ServiceArgs, INT ArgCount);
+BOOL GetDisplayName(LPCTSTR ServiceName);
/* print and error functions */
VOID PrintService(LPCTSTR ServiceName, LPSERVICE_STATUS_PROCESS pStatus, BOOL
bExtended);
@@ -83,5 +84,6 @@
VOID SetDescriptionUsage(VOID);
VOID SetConfigUsage(VOID);
VOID SetFailureUsage(VOID);
+VOID GetDisplayNameUsage(VOID);
#endif /* _SC_PCH_ */
Modified: trunk/reactos/base/applications/sc/usage.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/usage…
==============================================================================
--- trunk/reactos/base/applications/sc/usage.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/usage.c [iso-8859-1] Thu Jun 16 19:47:50 2016
@@ -43,8 +43,8 @@
_T("\t create : Creates a service (adds it to the registry).\n")
_T("\t control : Sends a control to a service.\n")
_T("\t sdshow : Displays a service's security descriptor.\n")
- _T("\t sdset : Sets a service's security descriptor.\n"));
-// "\t GetDisplayName : Gets the DisplayName for a service.\n")
+ _T("\t sdset : Sets a service's security descriptor.\n")
+ _T("\t GetDisplayName : Gets the DisplayName for a service.\n"));
// "\t GetKeyName : Gets the ServiceKeyName for a service.\n")
// "\t EnumDepend : Enumerates Service Dependencies.\n")
// "\n")
@@ -262,3 +262,11 @@
_T(" Valid actions are <run|restart|reboot>
>\n")
_T(" (Must be used in conjunction with the reset=
option)\n"));
}
+
+VOID GetDisplayNameUsage(VOID)
+{
+ _tprintf(_T("DESCRIPTION:\n")
+ _T(" Gets the display name associated with a particular
service\n")
+ _T("USAGE:\n")
+ _T(" sc <server> GetDisplayName <service key name>
<bufsize>\n"));
+}