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.

73 lines
1.8 KiB

  1. /*
  2. * ini file/registry manipulation
  3. *
  4. */
  5. #include "pch.hxx"
  6. #include "strconst.h"
  7. ASSERTDATA
  8. //
  9. // UINT RegGetKeyNumbers(HKEY hkRegDataBase, const TCHAR *szRegSection)
  10. // Enumerate KEYS in szRegSection and return number of keys (subsections).
  11. //
  12. // Return 0, if szRegSection is not found, or doesn't have subsections
  13. //
  14. // Created: 14 Oct. 1994 by YSt
  15. //
  16. // Modified 10 Nov. 1997 by YSt
  17. //
  18. UINT RegGetKeyNumbers(HKEY hkRegDataBase, const TCHAR *szRegSection)
  19. {
  20. LONG lRes;
  21. HKEY hkSection;
  22. DWORD iSubKey = 0;
  23. lRes = RegOpenKeyEx(hkRegDataBase, szRegSection, 0, KEY_READ, &hkSection);
  24. if(lRes != ERROR_SUCCESS) // Cannot open reg database
  25. return(0);
  26. // Get number of subkeys
  27. lRes = RegQueryInfoKey(hkSection, NULL, NULL, NULL, &iSubKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  28. RegCloseKey(hkSection);
  29. if(lRes == ERROR_SUCCESS)
  30. return((UINT) iSubKey);
  31. else
  32. return(0);
  33. }
  34. //
  35. // BOOL RegGetKeyNameFromIndex(HKEY hkRegDataBase, const TCHAR *szRegSection, UINT Index,
  36. // const TCHAR * szBuffer, UINT cbBuffer)
  37. //
  38. // Return name of key (subsection) from Index in szBuffer. cbBuffer has a size of szBuffer. You must
  39. // first call RegGetKeyNumbers for enumerating values.
  40. //
  41. // Created: 14 Oct. 1994 by YSt
  42. //
  43. BOOL RegGetKeyNameFromIndex(HKEY hkRegDataBase, const TCHAR *szRegSection, UINT Index,
  44. TCHAR * szBuffer, DWORD *pcbBuffer)
  45. {
  46. LONG lRes;
  47. HKEY hkSection;
  48. FILETIME ft;
  49. lRes = RegOpenKeyEx(hkRegDataBase, szRegSection, 0, KEY_READ, &hkSection);
  50. if(lRes != ERROR_SUCCESS) // Cannot open reg database
  51. return(FALSE);
  52. lRes = RegEnumKeyEx(hkSection, (DWORD) Index, szBuffer, pcbBuffer, NULL, NULL, NULL, &ft);
  53. RegCloseKey(hkSection);
  54. if(lRes != ERROR_SUCCESS)
  55. return (FALSE);
  56. return (TRUE);
  57. }