Source code of Windows XP (NT5)
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.

109 lines
3.3 KiB

  1. /*-----------------------------------------------**
  2. ** Copyright (c) 1998 Microsoft Corporation **
  3. ** All Rights reserved **
  4. ** **
  5. ** reg.c **
  6. ** **
  7. ** Functions for reading, writing, and deleting **
  8. ** registry keys **
  9. ** 07-01-98 a-clindh Created **
  10. **-----------------------------------------------*/
  11. #include "tsvs.h"
  12. ///////////////////////////////////////////////////////////////////////////////
  13. // i is the index of the KeyName variable in Global.cpp
  14. // nKeyValue is the value we want to store.
  15. ///////////////////////////////////////////////////////////////////////////////
  16. void SetRegKey(int i, LONG * nKeyValue)
  17. {
  18. HKEY hKey;
  19. DWORD dwDisposition;
  20. if (RegCreateKeyEx(HKEY_CURRENT_USER, szWinStaKey,
  21. 0, "REG_DWORD", REG_OPTION_NON_VOLATILE,
  22. KEY_ALL_ACCESS, 0, &hKey, &dwDisposition)
  23. == ERROR_SUCCESS) {
  24. //
  25. // write the key value to the registry
  26. //
  27. RegSetValueEx(hKey, KeyName[i], 0, REG_DWORD,
  28. (const BYTE *)nKeyValue,
  29. sizeof(DWORD));
  30. RegCloseKey(hKey);
  31. }
  32. }
  33. ///////////////////////////////////////////////////////////////////////////////
  34. // i is the index of the KeyName variable in Global.cpp
  35. ///////////////////////////////////////////////////////////////////////////////
  36. void DeleteRegKey(int i)
  37. {
  38. HKEY hKey;
  39. if (RegOpenKeyEx(HKEY_CURRENT_USER, szWinStaKey, 0,
  40. KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
  41. RegDeleteValue(hKey, KeyName[i]);
  42. RegCloseKey(hKey);
  43. }
  44. }
  45. ///////////////////////////////////////////////////////////////////////////////
  46. // returns TRUE if the registry key is there and FALSE if it isn't
  47. ///////////////////////////////////////////////////////////////////////////////
  48. BOOL CheckForRegKey(int i)
  49. {
  50. DWORD *dwKeyValue;
  51. HKEY hKey;
  52. DWORD dwType;
  53. DWORD dwSize;
  54. dwType = REG_SZ;
  55. dwSize = sizeof(DWORD);
  56. if (RegOpenKeyEx(HKEY_CURRENT_USER, szWinStaKey, 0,
  57. KEY_READ, &hKey) == ERROR_SUCCESS) {
  58. if (RegQueryValueEx(hKey, KeyName[i], 0,
  59. &dwType, (LPBYTE) &dwKeyValue,
  60. &dwSize) == ERROR_SUCCESS) {
  61. RegCloseKey(hKey);
  62. return TRUE;
  63. }
  64. RegCloseKey(hKey);
  65. }
  66. return FALSE;
  67. }
  68. ///////////////////////////////////////////////////////////////////////////////
  69. // pass the index of the KeyName variable and the function
  70. // returns the value stored in the registry
  71. ///////////////////////////////////////////////////////////////////////////////
  72. int GetRegKeyValue(int i)
  73. {
  74. int nKeyValue;
  75. HKEY hKey;
  76. DWORD dwType;
  77. DWORD dwSize;
  78. dwType = REG_SZ;
  79. dwSize = sizeof(DWORD);
  80. if (RegOpenKeyEx(HKEY_CURRENT_USER, szWinStaKey, 0,
  81. KEY_READ, &hKey) == ERROR_SUCCESS) {
  82. if (RegQueryValueEx(hKey, KeyName[i], 0,
  83. &dwType, (LPBYTE) &nKeyValue,
  84. &dwSize) == ERROR_SUCCESS) {
  85. RegCloseKey(hKey);
  86. return nKeyValue;
  87. }
  88. RegCloseKey(hKey);
  89. }
  90. return 0;
  91. }
  92. ///////////////////////////////////////////////////////////////////////////////