Author: ekohl
Date: Thu Jun 16 21:18:59 2016
New Revision: 71651
URL:
http://svn.reactos.org/svn/reactos?rev=71651&view=rev
Log:
[SC]
Add GetKeyName command.
Modified:
trunk/reactos/base/applications/sc/name.c
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/name.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/name.…
==============================================================================
--- trunk/reactos/base/applications/sc/name.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/name.c [iso-8859-1] Thu Jun 16 21:18:59 2016
@@ -73,3 +73,68 @@
return bResult;
}
+
+BOOL GetKeyName(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 (!GetServiceKeyName(hManager,
+ ServiceName,
+ NULL,
+ &BufferSize))
+ {
+ if (BufferSize == 0)
+ {
+ _tprintf(_T("[SC] GetServiceKeyName 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 (!GetServiceKeyName(hManager,
+ ServiceName,
+ pBuffer,
+ &BufferSize))
+ {
+ _tprintf(_T("[SC] GetServiceKeyName FAILED %lu:\n\n"),
GetLastError());
+ bResult = FALSE;
+ goto done;
+ }
+
+ _tprintf(_T("[SC] GetServiceKeyName SUCCESS Name = %s\n"), pBuffer);
+
+done:
+ if (bResult == FALSE)
+ ReportLastError();
+
+ if (pBuffer != NULL)
+ HeapFree(GetProcessHeap(), 0, pBuffer);
+
+ if (hManager)
+ CloseServiceHandle(hManager);
+
+ return bResult;
+}
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 21:18:59 2016
@@ -284,6 +284,18 @@
else
GetDisplayNameUsage();
}
+ else if (!lstrcmpi(Command, _T("GetKeyName")))
+ {
+ if (ArgCount > 0)
+ {
+ ServiceName = *ServiceArgs++;
+ ArgCount--;
+
+ GetKeyName(ServiceName);
+ }
+ else
+ GetKeyNameUsage();
+ }
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 21:18:59 2016
@@ -46,6 +46,7 @@
BOOL QueryFailure(LPCTSTR ServiceName);
BOOL SetFailure(LPCTSTR *ServiceArgs, INT ArgCount);
BOOL GetDisplayName(LPCTSTR ServiceName);
+BOOL GetKeyName(LPCTSTR ServiceName);
/* print and error functions */
VOID PrintService(LPCTSTR ServiceName, LPSERVICE_STATUS_PROCESS pStatus, BOOL
bExtended);
@@ -85,5 +86,6 @@
VOID SetConfigUsage(VOID);
VOID SetFailureUsage(VOID);
VOID GetDisplayNameUsage(VOID);
+VOID GetKeyNameUsage(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 21:18:59 2016
@@ -44,8 +44,8 @@
_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("\t GetDisplayName : Gets the DisplayName for a service.\n"));
-// "\t GetKeyName : Gets the ServiceKeyName for a service.\n")
+ _T("\t GetDisplayName : Gets the DisplayName for a service.\n")
+ _T("\t GetKeyName : Gets the ServiceKeyName for a service.\n"));
// "\t EnumDepend : Enumerates Service Dependencies.\n")
// "\n")
// "\tService Name Independant Commands:\n")
@@ -266,7 +266,16 @@
VOID GetDisplayNameUsage(VOID)
{
_tprintf(_T("DESCRIPTION:\n")
- _T(" Gets the display name associated with a particular
service\n")
+ _T(" Gets the display name associated with a particular
service.\n")
_T("USAGE:\n")
_T(" sc <server> GetDisplayName <service key name>
<bufsize>\n"));
}
+
+VOID GetKeyNameUsage(VOID)
+{
+ _tprintf(_T("DESCRIPTION:\n")
+ _T(" Gets the key name associated with a particular service,
using the\n")
+ _T(" display name as input.\n")
+ _T("USAGE:\n")
+ _T(" sc <server> GetKeyName <service display name>
<bufsize>\n"));
+}