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.

193 lines
5.6 KiB

  1. #include "globals.h"
  2. kNT4DevWalk::kNT4DevWalk(kLogFile *Proc, HWND hIn)
  3. {
  4. LogProc=Proc;
  5. hMainWnd=hIn;
  6. }
  7. BOOL kNT4DevWalk::Begin()
  8. {
  9. DWORD dwRet = 0;
  10. dwCurrentKey = 0;
  11. dwLevel2Key = 0;
  12. lstrcpy(szRootKeyString, "SYSTEM\\CurrentControlSet\\Enum\\Root");
  13. if (ERROR_SUCCESS == RegOpenKeyEx( HKEY_LOCAL_MACHINE, szRootKeyString, 0, KEY_READ, &hkeyRoot))
  14. return REG_SUCCESS;
  15. else
  16. return REG_FAILURE;
  17. return REG_FAILURE;
  18. }
  19. BOOL kNT4DevWalk::Walk()
  20. {
  21. DWORD dwIndex = 0;
  22. PTCHAR pName = NULL, pFull = NULL;
  23. DWORD dwSizeName = MAX_PATH * 4;
  24. pName = (PTCHAR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSizeName);
  25. if(!pName)
  26. return FALSE;
  27. pFull = (PTCHAR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSizeName);
  28. if(!pFull) {
  29. HeapFree(GetProcessHeap(), NULL, pName);
  30. return FALSE;
  31. }
  32. while (ERROR_SUCCESS == RegEnumKeyEx(hkeyRoot, dwIndex, pName, &dwSizeName, NULL, NULL, NULL, NULL)) {
  33. wsprintf(pFull, "SYSTEM\\CurrentControlSet\\Enum\\Root\\%s", pName);
  34. if (!lstrcmp(pName, "Control")) {
  35. GetKeyValues(pFull);
  36. }
  37. SearchSubKeys(pFull);
  38. dwSizeName = MAX_PATH * 4;
  39. dwIndex++;
  40. }
  41. HeapFree(GetProcessHeap(), NULL, pName);
  42. HeapFree(GetProcessHeap(), NULL, pFull);
  43. return TRUE;
  44. }
  45. BOOL kNT4DevWalk::SearchSubKeys(PTCHAR szName)
  46. {
  47. HKEY hKeyTemp;
  48. DWORD dwIndex = 0;
  49. PTCHAR szName2 = NULL;
  50. DWORD dwSizeName = MAX_PATH * 4;
  51. szName2 = (PTCHAR)malloc(MAX_PATH * 4);
  52. if(!szName2)
  53. return FALSE;
  54. if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hKeyTemp))
  55. {
  56. free(szName2);
  57. return FALSE;
  58. }
  59. while (ERROR_SUCCESS == RegEnumKeyEx(hKeyTemp, dwIndex, szName2, &dwSizeName, NULL, NULL, NULL, NULL))
  60. {
  61. TCHAR szFull[MAX_PATH * 4];
  62. wsprintf(szFull, "%s\\%s", szName, szName2);
  63. if (ERROR_SUCCESS == lstrcmp(szName2, "Control"))
  64. {
  65. GetKeyValues(szName);
  66. SearchSubKeys(szFull);
  67. dwSizeName = MAX_PATH * 4;
  68. dwIndex++;
  69. }
  70. }
  71. free(szName2);
  72. return TRUE;
  73. }
  74. BOOL kNT4DevWalk::GetKeyValues(PTCHAR szName)
  75. {
  76. HKEY hkeyUninstallKey;
  77. TCHAR szFullKey[MAX_PATH * 4];
  78. PTCHAR szProductName = NULL;
  79. DWORD dwProductSize = MAX_PATH * 4;
  80. DWORD dwType = REG_SZ;
  81. szProductName = (PTCHAR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_PATH * 4);
  82. if(!szProductName)
  83. return FALSE;
  84. wsprintf(szFullKey, "%s\\%s", szRootKeyString, szName);
  85. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hkeyUninstallKey))
  86. {
  87. LogProc->LogString(",%s,", szName);
  88. szProductName[0] = 0;
  89. dwProductSize = MAX_PATH * 4;
  90. if (ERROR_SUCCESS == RegQueryValueEx(hkeyUninstallKey, "Class", NULL, &dwType, (PBYTE)szProductName, &dwProductSize)
  91. && lstrlen(szProductName) != 0)
  92. {
  93. LogProc->LogString("%s,", szProductName);
  94. }
  95. else
  96. {
  97. LogProc->LogString("NULL,");
  98. }
  99. szProductName[0] = 0;
  100. dwProductSize = MAX_PATH * 4;
  101. if (ERROR_SUCCESS == RegQueryValueEx(hkeyUninstallKey, "DeviceDesc", NULL, &dwType, (PBYTE)szProductName, &dwProductSize)
  102. && lstrlen(szProductName) != 0)
  103. {
  104. LogProc->StripCommas(szProductName);
  105. LogProc->LogString("%s,", szProductName);
  106. }
  107. else
  108. LogProc->LogString("NULL,");
  109. lstrcpy(szProductName, "");
  110. dwProductSize = MAX_PATH * 4;
  111. if (ERROR_SUCCESS == RegQueryValueEx(hkeyUninstallKey, "HardWareID", NULL, &dwType, (PBYTE)szProductName, &dwProductSize)
  112. && lstrlen(szProductName)!=0)
  113. {
  114. LogProc->StripCommas(szProductName);
  115. LogProc->LogString("%s,", szProductName);
  116. }
  117. else
  118. LogProc->LogString("NULL,");
  119. szProductName[0] = 0;
  120. dwProductSize = MAX_PATH * 4;
  121. if (ERROR_SUCCESS == RegQueryValueEx(hkeyUninstallKey, "Mfg", NULL, &dwType, (PBYTE)szProductName, &dwProductSize)
  122. && lstrlen(szProductName) != 0)
  123. {
  124. LogProc->StripCommas(szProductName);
  125. LogProc->LogString("%s,", szProductName);
  126. }
  127. else
  128. LogProc->LogString("NULL,");
  129. szProductName[0] = 0;
  130. wsprintf(szFullKey, "%s\\Control", szName);
  131. HKEY hkTemp;
  132. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, szFullKey, 0, KEY_READ, &hkTemp))
  133. {
  134. dwProductSize = MAX_PATH * 4;
  135. if (ERROR_SUCCESS == RegQueryValueEx(hkTemp, "ActiveService", NULL, &dwType, (PBYTE)szProductName, &dwProductSize)
  136. && lstrlen(szProductName) != 0)
  137. {
  138. LogProc->StripCommas(szProductName);
  139. LogProc->LogString("%s,\r\n", szProductName);
  140. }
  141. else
  142. LogProc->LogString("NULL,\r\n");
  143. szProductName[0] = 0;
  144. RegCloseKey(hkTemp);
  145. }
  146. else
  147. LogProc->LogString("NULL,\r\n");
  148. }
  149. else
  150. {
  151. HeapFree(GetProcessHeap(), NULL, szProductName);
  152. return REG_FAILURE;
  153. }
  154. HeapFree(GetProcessHeap(), NULL, szProductName);
  155. RegCloseKey(hkeyUninstallKey);
  156. return REG_SUCCESS;
  157. }