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.

143 lines
3.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: ZAPKNOWN.C
  7. //
  8. // Contents: This tool will remove the OLE KnownDLL's entries from the
  9. // registry.
  10. //----------------------------------------------------------------------------
  11. #include <windows.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. void ZapEntry(HKEY hKnownKey, char *pszEntry)
  15. {
  16. long l;
  17. l = RegDeleteValue(hKnownKey, pszEntry);
  18. if (l == ERROR_FILE_NOT_FOUND)
  19. {
  20. printf("FYI: %s isn't in the KnownDLL list (no problem)\n",pszEntry);
  21. } else if(l != ERROR_SUCCESS)
  22. {
  23. printf("Warning: Could not delete %s (error 0x%x)\n",pszEntry,l);
  24. }
  25. }
  26. void AddExcludeEntry(HKEY hSesMan, char *pszEntry)
  27. {
  28. long l, cbSize, cbEntry, cbTotal;
  29. DWORD dwType;
  30. char *pBuffer, *ptr, *pEnd;
  31. cbEntry = strlen(pszEntry);
  32. l = RegQueryValueEx(hSesMan, "ExcludeFromKnownDlls", 0,
  33. &dwType, 0, &cbSize);
  34. if(ERROR_SUCCESS != l)
  35. {
  36. printf("Creating HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\ExcludeFromKnownDlls\n");
  37. cbSize = 1;
  38. }
  39. cbTotal = cbSize + cbEntry+1;
  40. pBuffer = GlobalAlloc(0, cbTotal);
  41. if(ERROR_SUCCESS == l)
  42. {
  43. l = RegQueryValueEx(hSesMan, "ExcludeFromKnownDlls", 0,
  44. &dwType, pBuffer, &cbSize);
  45. }
  46. //
  47. // It succeeded above but now it fails ??
  48. //
  49. if(ERROR_SUCCESS != l || REG_MULTI_SZ != dwType)
  50. {
  51. printf("Sorry, Problems reading 'Session Manager\\ExcludeFromKnownDlls'\n");
  52. exit(0);
  53. }
  54. ptr = pBuffer;
  55. pEnd = pBuffer+cbSize-1;
  56. while(ptr < pEnd)
  57. {
  58. // if it is already there. when we are done.
  59. if(0 == strcmp(ptr, pszEntry))
  60. return;
  61. // Scan to end of the string and then onto the next string.
  62. while(ptr < pEnd && *ptr != '\0')
  63. ++ptr;
  64. ++ptr;
  65. }
  66. strcpy(pBuffer + cbSize-1, pszEntry);
  67. pBuffer[cbTotal-1] = '\0'; // The second NULL
  68. l = RegSetValueEx(hSesMan, "ExcludeFromKnownDlls", 0,
  69. REG_MULTI_SZ, pBuffer, cbTotal);
  70. if(ERROR_SUCCESS != l)
  71. {
  72. printf("Error writing 'Session Manager\\ExcludeFromKnownDlls'\n");
  73. exit(0);
  74. }
  75. }
  76. HKEY hSesMan, hKnownKey;
  77. void ExcludeDll(char *pszDll)
  78. {
  79. ZapEntry(hKnownKey, pszDll);
  80. AddExcludeEntry(hSesMan, pszDll);
  81. }
  82. int _cdecl main(
  83. int argc,
  84. char *argv[]
  85. ) {
  86. long l;
  87. DWORD dwRegValueType;
  88. CHAR sz[2048];
  89. ULONG ulSize;
  90. l = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  91. "SYSTEM\\CurrentControlSet\\Control\\Session Manager",
  92. 0,
  93. KEY_QUERY_VALUE | KEY_SET_VALUE,
  94. &hSesMan );
  95. if(ERROR_SUCCESS != l)
  96. {
  97. printf("Failed to open HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\n");
  98. printf("Do you have administrator privleges?\n");
  99. exit(1);
  100. }
  101. l = RegOpenKeyEx(hSesMan, "KnownDlls", 0,
  102. KEY_QUERY_VALUE | KEY_SET_VALUE, &hKnownKey);
  103. if(ERROR_SUCCESS != l)
  104. {
  105. printf("Failed to open HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\KnownDlls\n");
  106. printf("Do you have administrator privleges?\n");
  107. exit(1);
  108. }
  109. //
  110. // Delete OLE32.DLL, OLETHK32.DLL, OLEPRX32.DLL, and OLECNV32.DLL
  111. //
  112. ExcludeDll("OLE32");
  113. ExcludeDll("OLEAUT32");
  114. ExcludeDll("OLETHK32");
  115. ExcludeDll("OLECNV32");
  116. l = RegCloseKey( hSesMan );
  117. l = RegCloseKey( hKnownKey );
  118. return(0);
  119. }