Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.3 KiB

  1. //=================================================================
  2. //
  3. // NTDEVTOSVCSEARCH.CPP -- Class to use the registry to find an
  4. // NT Service name based on a device name.
  5. //
  6. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  7. //
  8. // Revisions: 09/18/97 a-sanjes Created
  9. //
  10. //=================================================================
  11. #include "precomp.h"
  12. #include <winerror.h>
  13. #include <cregcls.h>
  14. #include "ntdevtosvcsearch.h"
  15. #ifdef NTONLY
  16. //////////////////////////////////////////////////////////////////////////////
  17. //
  18. // ntdevtosvcsearch.cpp - Class implementation of CNTDeviceToServiceSearch.
  19. //
  20. // This class is intended to provide a way for an NT implementation to locate
  21. // an NT Service name based off of an owner device name given to it by the
  22. // HAL Layer. For example, we may be working with KeyboardPort0, but actually
  23. // need to report a service name of i8042prt (what scares me is that I
  24. // pulled "i8042prt" out of memory. Someone shoot me now).
  25. //
  26. //////////////////////////////////////////////////////////////////////////////
  27. //////////////////////////////////////////////////////////////////////////////
  28. //
  29. // FUNCTION : CNTDeviceToServiceSearch::CNTDeviceToServiceSearch
  30. //
  31. // DESCRIPTION : Constructor
  32. //
  33. // INPUTS : none.
  34. //
  35. // OUTPUTS : none
  36. //
  37. // RETURNS : nothing
  38. //
  39. // COMMENTS : none.
  40. //
  41. //////////////////////////////////////////////////////////////////////////////
  42. CNTDeviceToServiceSearch::CNTDeviceToServiceSearch( void )
  43. : CRegistrySearch()
  44. {
  45. }
  46. //////////////////////////////////////////////////////////////////////////////
  47. //
  48. // FUNCTION : CNTDeviceToServiceSearch::~CNTDeviceToServiceSearch
  49. //
  50. // DESCRIPTION : Destructor
  51. //
  52. // INPUTS : none
  53. //
  54. // OUTPUTS : none
  55. //
  56. // RETURNS : nothing
  57. //
  58. // COMMENTS : Class destructor
  59. //
  60. //////////////////////////////////////////////////////////////////////////////
  61. CNTDeviceToServiceSearch::~CNTDeviceToServiceSearch( void )
  62. {
  63. }
  64. //////////////////////////////////////////////////////////////////////////////
  65. //
  66. // FUNCTION : CNTDeviceToServiceSearch::Find
  67. //
  68. // DESCRIPTION : Traverses registry, looking for the supplied owner
  69. // device name (obtained from the HAL) and upon finding
  70. // it, stores the name in strServiceName.
  71. //
  72. // INPUTS : LPCTSTR pszOwnerDeviceName - Owner Device name to
  73. // locate.
  74. //
  75. // OUTPUTS : CHString& strServiceName - Service name found in
  76. // registry.
  77. //
  78. // RETURNS : BOOL TRUE/FALSE - Success/Failure
  79. //
  80. // COMMENTS : Only applicable to Windows NT. Searches the following key:
  81. // HKLM\HARDWARE\RESOURCEMAP.
  82. //
  83. //////////////////////////////////////////////////////////////////////////////
  84. BOOL CNTDeviceToServiceSearch::Find( LPCTSTR pszOwnerDeviceName, CHString& strServiceName )
  85. {
  86. //////////////////////////////////////////////////////////////////////////
  87. //
  88. // We will need to traverse the HKEY_LOCAL_MACHINE\HARDWARE\RESOURCE_MAP
  89. // tree in order to locate the correct service name.
  90. //
  91. // A SubKey Name will identify an owner if it:
  92. //
  93. // a> Matches the pszOwnerDeviceName that was passed in
  94. // b> We successfully query a value for the Raw
  95. // or translated device name. The Raw device
  96. // name is something along the lines of
  97. // \Device\PointerPort0.Raw and the Translated
  98. // device name is something along the lines of
  99. // \Device\PointerPort0.Translated. In either
  100. // case, replace "PointerPort0" with the value
  101. // of pszOwnerDeviceName.
  102. //
  103. //////////////////////////////////////////////////////////////////////////
  104. CHString strRawDeviceValue,
  105. strTranslatedDeviceValue,
  106. strServiceNamePath;
  107. LPCTSTR ppszValueNames[2];
  108. strRawDeviceValue.Format( RAWVALUENAME_FMAT, pszOwnerDeviceName );
  109. strTranslatedDeviceValue.Format( TRANSLATEDVALUENAME_FMAT, pszOwnerDeviceName );
  110. ppszValueNames[0] = (LPCTSTR) strRawDeviceValue;
  111. ppszValueNames[1] = (LPCTSTR) strTranslatedDeviceValue;
  112. // We're all setup, so go ahead and traverse the registry
  113. return LocateKeyByNameOrValueName( HKEY_LOCAL_MACHINE,
  114. DEVTOSVC_BASEKEYPATH,
  115. pszOwnerDeviceName,
  116. ppszValueNames,
  117. 2,
  118. strServiceName,
  119. strServiceNamePath );
  120. }
  121. #endif