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.

156 lines
4.0 KiB

  1. #include "globals.h"
  2. kNT5NetWalk::kNT5NetWalk(kLogFile *Proc, HWND hIn)
  3. {
  4. LogProc=Proc;
  5. hMainWnd=hIn;
  6. }
  7. BOOL kNT5NetWalk::Begin()
  8. {
  9. DWORD dwRet=0;
  10. dwCurrentKey=0;
  11. dwLevel2Key=0;
  12. strcpy(szRootKeyString, "SYSTEM\\CurrentControlSet\\Control\\Network");
  13. dwRet=RegOpenKeyEx(
  14. HKEY_LOCAL_MACHINE,
  15. szRootKeyString,
  16. 0,
  17. KEY_READ,
  18. &hkeyRoot);
  19. if (dwRet==ERROR_SUCCESS)
  20. {
  21. //MessageBox(GetFocus(), "Returning REG_SUCCESS", "SP", MB_OK);
  22. return REG_SUCCESS;
  23. }
  24. else
  25. {
  26. char szMessage[1024];
  27. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, dwRet,
  28. NULL, szMessage, 1024, 0);
  29. printf("**********\r\n");
  30. printf("%s[%d] Error: %s", __FILE__, __LINE__, szMessage);
  31. printf("**********\r\n");
  32. //MessageBox(GetFocus(), "Returning REG_FAIL", "SP", MB_OK);
  33. return REG_FAILURE;
  34. }
  35. //else if (dwPlatform==PLATFORM_NT)
  36. //MessageBox(GetFocus(), "Returning REG_FAIL", "SP", MB_OK);
  37. return REG_FAILURE;
  38. }
  39. BOOL kNT5NetWalk::Walk()
  40. {
  41. DWORD dwIndex = 0;
  42. PTCHAR szName = NULL;
  43. DWORD dwSizeName = MAX_PATH * 4;
  44. LogProc->LogString(",#NT5_Net_Components,,\r\n");
  45. szName = (PTCHAR)malloc(dwSizeName);
  46. if(!szName) {
  47. return FALSE;
  48. }
  49. while (ERROR_SUCCESS == RegEnumKeyEx(hkeyRoot, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, NULL))
  50. {
  51. TCHAR szFull[MAX_PATH * 4];
  52. wsprintf(szFull, "SYSTEM\\CurrentControlSet\\Control\\Network\\%s", szName);
  53. GetKeyValues(szFull);
  54. SearchSubKeys(szFull);
  55. dwSizeName = MAX_PATH * 4;
  56. dwIndex++;
  57. }
  58. return TRUE;
  59. }
  60. BOOL kNT5NetWalk::SearchSubKeys(PTCHAR szName)
  61. {
  62. HKEY hKeyTemp;
  63. DWORD dwRet = 0;
  64. PTCHAR szName2 = NULL;
  65. DWORD dwIndex = 0;
  66. DWORD dwSizeName = MAX_PATH * 4;
  67. TCHAR szFull[MAX_PATH * 4];
  68. if(!szName)
  69. return FALSE;
  70. szName2 = (PTCHAR)malloc(MAX_PATH * 4);
  71. if(!szName2)
  72. return FALSE;
  73. if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hKeyTemp)) {
  74. free(szName2);
  75. return FALSE;
  76. }
  77. while (ERROR_SUCCESS == RegEnumKeyEx(hKeyTemp, dwIndex, szName2, &dwSizeName, NULL, NULL, NULL, NULL)) {
  78. wsprintf(szFull, "%s\\%s", szName, szName2);
  79. GetKeyValues(szFull);
  80. SearchSubKeys(szFull);
  81. dwSizeName = MAX_PATH * 4;
  82. dwIndex++;
  83. }
  84. free(szName2);
  85. return TRUE;
  86. }
  87. BOOL kNT5NetWalk::GetKeyValues(char *szName)
  88. {
  89. HKEY hkeyUninstallKey;
  90. char szFullKey[1024];
  91. PUCHAR szProductName=(PUCHAR)malloc(1024);
  92. DWORD dwProductSize=1024;
  93. DWORD dwRet=0;
  94. DWORD dwType=REG_SZ;
  95. strcpy(szFullKey, szRootKeyString);
  96. strcat(szFullKey, "\\");
  97. strcat(szFullKey, szName);
  98. dwRet=RegOpenKeyEx(HKEY_LOCAL_MACHINE, szName, 0,
  99. KEY_READ, &hkeyUninstallKey);
  100. if (dwRet==ERROR_SUCCESS)
  101. {
  102. dwRet=RegQueryValueEx(hkeyUninstallKey, "ComponentId", NULL, &dwType,
  103. szProductName, &dwProductSize);
  104. if (dwRet==ERROR_SUCCESS)
  105. {
  106. printf("Product = %s\r\n", szProductName);
  107. LogProc->StripCommas((char*)szProductName);
  108. LogProc->LogString(",%s,\r\n", szProductName);
  109. free(szProductName);
  110. RegCloseKey(hkeyUninstallKey);
  111. return REG_SUCCESS;
  112. }
  113. /*
  114. else
  115. {
  116. printf("Product = %s\r\n", szName);
  117. LogProc->StripCommas(szName);
  118. LogProc->LogString(",%s,\r\n", szName);
  119. free(szProductName);
  120. RegCloseKey(hkeyUninstallKey);
  121. return REG_SUCCESS;
  122. //Check for other ways to get product name
  123. }
  124. */
  125. }
  126. else
  127. {
  128. char szMessage[1024];
  129. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, dwRet,
  130. NULL, szMessage, 1024, 0);
  131. printf("**********\r\n");
  132. printf("%s[%d] Error: %s",__FILE__, __LINE__, szMessage);
  133. printf("**********\r\n");
  134. free(szProductName);
  135. RegCloseKey(hkeyUninstallKey);
  136. return REG_FAILURE;
  137. }
  138. free(szProductName);
  139. RegCloseKey(hkeyUninstallKey);
  140. return REG_FAILURE;
  141. }