Add GetKeyName command.

svn path=/trunk/; revision=71651
This commit is contained in:
Eric Kohl 2016-06-16 21:18:59 +00:00
parent 2df110e92d
commit 47dae4bd05
4 changed files with 91 additions and 3 deletions

View file

@ -73,3 +73,68 @@ done:
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;
}

View file

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

View file

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

View file

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