Add GetDisplayName command.

svn path=/trunk/; revision=71648
This commit is contained in:
Eric Kohl 2016-06-16 19:47:50 +00:00
parent ffe9e79d41
commit 7d66c9341d
5 changed files with 100 additions and 2 deletions

View file

@ -9,6 +9,7 @@ list(APPEND SOURCE
description.c
failure.c
misc.c
name.c
print.c
query.c
sc.c

View file

@ -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;
}

View file

@ -272,6 +272,18 @@ ScControl(LPCTSTR Server, // remote machine name
{
SetFailure(ServiceArgs, ArgCount);
}
else if (!lstrcmpi(Command, _T("GetDisplayName")))
{
if (ArgCount > 0)
{
ServiceName = *ServiceArgs++;
ArgCount--;
GetDisplayName(ServiceName);
}
else
GetDisplayNameUsage();
}
else
{
MainUsage();

View file

@ -45,6 +45,7 @@ BOOL QueryDescription(LPCTSTR ServiceName);
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 QueryFailureUsage(VOID);
VOID SetDescriptionUsage(VOID);
VOID SetConfigUsage(VOID);
VOID SetFailureUsage(VOID);
VOID GetDisplayNameUsage(VOID);
#endif /* _SC_PCH_ */

View file

@ -43,8 +43,8 @@ VOID MainUsage(VOID)
_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 @@ VOID SetFailureUsage(VOID)
_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"));
}