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.

134 lines
2.3 KiB

  1. #include "nc.h"
  2. #pragma hdrstop
  3. BOOL
  4. GetNcConfig(
  5. PCONFIG_DATA ConfigData
  6. )
  7. {
  8. HKEY hKey;
  9. LONG rVal;
  10. DWORD RegType;
  11. DWORD RegSize;
  12. WCHAR Buffer[4096];
  13. rVal = RegCreateKey(
  14. HKEY_LOCAL_MACHINE,
  15. REGKEY_PROVIDER,
  16. &hKey
  17. );
  18. if (rVal != ERROR_SUCCESS) {
  19. DebugPrint(( TEXT("could not create/open registry key") ));
  20. return FALSE;
  21. }
  22. RegSize = sizeof(Buffer);
  23. rVal = RegQueryValueEx(
  24. hKey,
  25. REGVAL_SERVER,
  26. 0,
  27. &RegType,
  28. (LPBYTE) Buffer,
  29. &RegSize
  30. );
  31. if (rVal == ERROR_SUCCESS) {
  32. ConfigData->ServerName = StringDup( Buffer );
  33. } else {
  34. ConfigData->ServerName = NULL;
  35. }
  36. RegSize = sizeof(Buffer);
  37. rVal = RegQueryValueEx(
  38. hKey,
  39. REGVAL_USERNAME,
  40. 0,
  41. &RegType,
  42. (LPBYTE) Buffer,
  43. &RegSize
  44. );
  45. if (rVal == ERROR_SUCCESS) {
  46. ConfigData->UserName = StringDup( Buffer );
  47. } else {
  48. ConfigData->UserName = NULL;
  49. }
  50. RegSize = sizeof(Buffer);
  51. rVal = RegQueryValueEx(
  52. hKey,
  53. REGVAL_PASSWORD,
  54. 0,
  55. &RegType,
  56. (LPBYTE) Buffer,
  57. &RegSize
  58. );
  59. if (rVal == ERROR_SUCCESS) {
  60. ConfigData->Password = StringDup( Buffer );
  61. } else {
  62. ConfigData->Password = NULL;
  63. }
  64. RegCloseKey( hKey );
  65. return TRUE;
  66. }
  67. BOOL
  68. SetNcConfig(
  69. PCONFIG_DATA ConfigData
  70. )
  71. {
  72. HKEY hKey;
  73. LONG rVal;
  74. rVal = RegCreateKey(
  75. HKEY_LOCAL_MACHINE,
  76. REGKEY_PROVIDER,
  77. &hKey
  78. );
  79. if (rVal != ERROR_SUCCESS) {
  80. DebugPrint(( TEXT("could not create/open registry key") ));
  81. return FALSE;
  82. }
  83. rVal = RegSetValueEx(
  84. hKey,
  85. REGVAL_SERVER,
  86. 0,
  87. REG_SZ,
  88. (LPBYTE) ConfigData->ServerName,
  89. StringSize( ConfigData->ServerName )
  90. );
  91. rVal = RegSetValueEx(
  92. hKey,
  93. REGVAL_USERNAME,
  94. 0,
  95. REG_SZ,
  96. (LPBYTE) ConfigData->UserName,
  97. StringSize( ConfigData->UserName )
  98. );
  99. rVal = RegSetValueEx(
  100. hKey,
  101. REGVAL_PASSWORD,
  102. 0,
  103. REG_SZ,
  104. (LPBYTE) ConfigData->Password,
  105. StringSize( ConfigData->Password )
  106. );
  107. RegCloseKey( hKey );
  108. return TRUE;
  109. }