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.

102 lines
2.4 KiB

  1. #include "wudetect.h"
  2. /////////////////////////////////////////////////////////////////////////////
  3. // CExpressionParser::fDetectRegKeyExists
  4. // Detect a substring in registry datum.
  5. //
  6. // Form: E=RegKeyExists,<root registry key>, <relative registry path>,[<value name>, [<data type>[, data]]]RegSubstr,<SubStr>,<RootKey>,<KeyPath>,<RegValue>,<RegData>
  7. /////////////////////////////////////////////////////////////////////////////
  8. const DWORD WU_MAX_COMPARISON_LEN = 3;
  9. const DWORD WU_MAX_VERSION_LEN = 30;
  10. bool CExpressionParser::fDetectRegKeyExists(TCHAR * pszBuf)
  11. {
  12. bool fSuccess = false;
  13. HKEY hKeyRoot;
  14. HKEY hKey;
  15. DWORD type;
  16. TCHAR szRegRoot[MAX_PATH];
  17. TCHAR szTargetKeyName[MAX_PATH];
  18. TCHAR szTargetKeyValue[MAX_PATH];
  19. TCHAR szBuf[MAX_PATH];
  20. DWORD dwStatus;
  21. DWORD iToken = 0;
  22. // Get reg root type (HKLM, etc)
  23. if ( fMapRegRoot(pszBuf, ++iToken, &hKeyRoot) &&
  24. (GetStringField2(pszBuf, ++iToken, szTargetKeyName, sizeof(szTargetKeyName)/sizeof(TCHAR)) != 0) )
  25. {
  26. // see if the reg key is there.
  27. if ( RegOpenKeyEx( hKeyRoot,
  28. szTargetKeyName,
  29. 0,
  30. KEY_QUERY_VALUE,
  31. &hKey) == ERROR_SUCCESS )
  32. {
  33. if ( GetStringField2(pszBuf, ++iToken, szTargetKeyValue, sizeof(szTargetKeyValue)/sizeof(TCHAR)) != 0 )
  34. {
  35. TargetRegValue targetValue;
  36. dwStatus = dwParseValue(iToken, pszBuf, targetValue);
  37. if ( dwStatus == ERROR_SUCCESS )
  38. {
  39. ActualKeyValue keyvalue;
  40. DWORD size = sizeof(keyvalue);
  41. if ( RegQueryValueEx(hKey,
  42. targetValue.szName,
  43. 0,
  44. &type,
  45. (BYTE *)&keyvalue,
  46. &size) == ERROR_SUCCESS )
  47. {
  48. switch ( targetValue.type )
  49. {
  50. case REG_NONE:
  51. {
  52. fSuccess = true;
  53. break;
  54. }
  55. case REG_DWORD:
  56. {
  57. if ( (type == REG_DWORD) ||
  58. ((type == REG_BINARY) && (size >= sizeof(DWORD))) )
  59. {
  60. // see if we have a match
  61. if ( targetValue.dw == keyvalue.dw )
  62. {
  63. fSuccess = true;
  64. }
  65. }
  66. break;
  67. }
  68. case REG_SZ:
  69. {
  70. if ( type == REG_SZ )
  71. {
  72. if ( lstrcmpi(targetValue.sz, keyvalue.sz) == 0 )
  73. {
  74. fSuccess = true;
  75. }
  76. }
  77. break;
  78. }
  79. } // switch
  80. }
  81. }
  82. }
  83. else
  84. {
  85. // no REG value so, REGPATH is sufficient to determine
  86. // installation.
  87. fSuccess = true;
  88. }
  89. RegCloseKey(hKey);
  90. }
  91. }
  92. return fSuccess;
  93. }