GetServiceKeyName
The GetServiceKeyName function retrieves the service name of the specified service.
BOOL GetServiceKeyName( SC_HANDLE hSCManager, LPCTSTR lpDisplayName, LPTSTR lpServiceName, LPDWORD lpcchBuffer );
Parameters
-
hSCManager
- [in] Handle to a computer's service control manager database, as returned by OpenSCManager. lpDisplayName
- [in] Pointer to a null-terminated string that specifies the service display name. It is best to choose a name that is less than 256 characters. lpServiceName
-
[out] Pointer to a buffer that receives the service name. If the function fails, this buffer will contain an empty string.
The maximum size of this array is 4K bytes. To determine the required size, specify NULL for this parameter and 0 for the lpcchBuffer parameter. The function will fail and GetLastError will return ERROR_INSUFFICIENT_BUFFER. The lpcchBuffer parameter will receive the required size.
lpcchBuffer
-
[in, out] Pointer to variable that specifies the size of the buffer pointed to by the
lpServiceName parameter, in
TCHARs. When the function returns, this parameter contains the size of the service name, in
TCHARs, excluding the null-terminating character.
If the buffer pointed to by lpServiceName is too small to contain the service name, the function stores no data in it. When the function returns, lpcchBuffer contains the size of the service name, excluding the NULL terminator.
Return Values
If the functions succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
There are two names for a service: the service name and the display name. The service name is the name of the service's key in the registry. The display name is a user-friendly name that appears in the Services control panel application, and is used with the NET START command. To map the service name to the display name, use the GetServiceDisplayName function. To map the display name to the service name, use the GetServiceKeyName function.
Requirements
Client | Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 3.5 and later. |
---|---|
Server | Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 3.5 and later. |
Header | Declared in Winsvc.h; include Windows.h. |
Library | Link to Advapi32.lib. |
DLL | Requires Advapi32.dll. |
Unicode | Implemented as GetServiceKeyNameW (Unicode) and GetServiceKeyNameA (ANSI). |