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.

114 lines
2.6 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1993 **
  4. //*********************************************************************
  5. #include "admincfg.h"
  6. UINT WriteRegistryDWordValue(HKEY hkeyRoot,CHAR * pszKeyName,CHAR * pszValueName,
  7. DWORD dwValue)
  8. {
  9. HKEY hKey;
  10. UINT uRet;
  11. if (!pszKeyName || !pszValueName)
  12. return ERROR_INVALID_PARAMETER;
  13. // create the key with appropriate name
  14. if ( (uRet = RegCreateKey(hkeyRoot,pszKeyName,&hKey))
  15. != ERROR_SUCCESS)
  16. return uRet;
  17. uRet = RegSetValueEx(hKey,pszValueName,0,REG_DWORD,
  18. (CHAR *) &dwValue,sizeof(dwValue));
  19. RegCloseKey(hKey);
  20. return uRet;
  21. }
  22. UINT ReadRegistryDWordValue(HKEY hkeyRoot,CHAR * pszKeyName,CHAR * pszValueName,
  23. DWORD * pdwValue)
  24. {
  25. HKEY hKey;
  26. UINT uRet;
  27. DWORD dwType,dwSize = sizeof(DWORD);
  28. if (!pszKeyName || !pszValueName)
  29. return ERROR_INVALID_PARAMETER;
  30. *pdwValue = 0;
  31. // open appropriate key
  32. if ( (uRet = RegOpenKey(hkeyRoot,pszKeyName,&hKey))
  33. != ERROR_SUCCESS)
  34. return uRet;
  35. uRet = RegQueryValueEx(hKey,pszValueName,0,&dwType,
  36. (CHAR *) pdwValue,&dwSize);
  37. RegCloseKey(hKey);
  38. return uRet;
  39. }
  40. UINT WriteRegistryStringValue(HKEY hkeyRoot,CHAR * pszKeyName,CHAR * pszValueName,
  41. CHAR * pszValue, BOOL bExpandable)
  42. {
  43. HKEY hKey;
  44. UINT uRet;
  45. if (!pszKeyName || !pszValueName)
  46. return ERROR_INVALID_PARAMETER;
  47. // create the key with appropriate name
  48. if ( (uRet = RegCreateKey(hkeyRoot,pszKeyName,&hKey))
  49. != ERROR_SUCCESS)
  50. return uRet;
  51. uRet = RegSetValueEx(hKey,pszValueName,0,
  52. bExpandable ? REG_EXPAND_SZ : REG_SZ,
  53. (CHAR *) pszValue,lstrlen(pszValue)+1);
  54. RegCloseKey(hKey);
  55. return uRet;
  56. }
  57. UINT ReadRegistryStringValue(HKEY hkeyRoot,CHAR * pszKeyName,CHAR * pszValueName,
  58. CHAR * pszValue,UINT cbValue)
  59. {
  60. HKEY hKey;
  61. UINT uRet;
  62. DWORD dwType;
  63. DWORD dwSize = cbValue;
  64. if (!pszKeyName || !pszValueName)
  65. return ERROR_INVALID_PARAMETER;
  66. // create the key with appropriate name
  67. if ( (uRet = RegOpenKey(hkeyRoot,pszKeyName,&hKey))
  68. != ERROR_SUCCESS)
  69. return uRet;
  70. uRet = RegQueryValueEx(hKey,pszValueName,0,&dwType,
  71. (CHAR *) pszValue,&dwSize);
  72. RegCloseKey(hKey);
  73. return uRet;
  74. }
  75. UINT DeleteRegistryValue(HKEY hkeyRoot,CHAR * pszKeyName,CHAR * pszValueName)
  76. {
  77. HKEY hKey;
  78. UINT uRet;
  79. if (!pszKeyName || !pszValueName)
  80. return ERROR_INVALID_PARAMETER;
  81. // create the key with appropriate name
  82. if ( (uRet = RegOpenKey(hkeyRoot,pszKeyName,&hKey))
  83. != ERROR_SUCCESS)
  84. return uRet;
  85. uRet = RegDeleteValue(hKey,pszValueName);
  86. RegCloseKey(hKey);
  87. return uRet;
  88. }