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.

179 lines
3.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: UPKNOWN.C
  7. //
  8. // Contents: This tool will add the three OLE2 DLL's to the known list
  9. // for wow.
  10. //----------------------------------------------------------------------------
  11. #include <windows.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. void FindAndDelete(
  15. char *psz,
  16. char *pszDeleteString
  17. )
  18. {
  19. char *substr;
  20. char temp[1024];
  21. char *pstr;
  22. if ( psz == NULL )
  23. {
  24. return;
  25. }
  26. while ( TRUE ) {
  27. substr = strstr(psz,pszDeleteString);
  28. if ( substr == NULL ) {
  29. break;
  30. }
  31. pstr = substr;
  32. if ((substr > psz) && (substr[-1] == ' '))
  33. {
  34. substr--;
  35. }
  36. *substr=0;
  37. strcat(psz,pstr+strlen(pszDeleteString));
  38. }
  39. }
  40. void FindOrAdd(
  41. char *psz,
  42. char *pszAddition
  43. ) {
  44. char *substr;
  45. char temp[1024];
  46. char ch;
  47. strcpy(temp," ");
  48. strcat(temp,pszAddition);
  49. substr = psz;
  50. while ( TRUE ) {
  51. substr = strstr(substr,temp);
  52. if ( substr == NULL ) {
  53. break;
  54. }
  55. ch = *(substr+strlen(temp));
  56. if ( ch = ' ' || ch == '\0' ) {
  57. break;
  58. }
  59. }
  60. if ( substr == NULL )
  61. {
  62. strcat( psz, temp );
  63. }
  64. }
  65. int _cdecl main(
  66. int argc,
  67. char *argv[]
  68. ) {
  69. HKEY WowKey;
  70. long l;
  71. DWORD dwRegValueType;
  72. CHAR sz[2048];
  73. ULONG ulSize;
  74. l = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  75. "SYSTEM\\CurrentControlSet\\Control\\WOW",
  76. 0,
  77. KEY_QUERY_VALUE | KEY_SET_VALUE,
  78. &WowKey );
  79. if ( l != 0 ) {
  80. printf("Failed to open HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\WOW\n");
  81. printf("Do you have administrator privleges?\n");
  82. exit(1);
  83. }
  84. ulSize = sizeof(sz);
  85. l = RegQueryValueEx( WowKey,
  86. "KnownDLLs",
  87. NULL,
  88. &dwRegValueType,
  89. sz,
  90. &ulSize );
  91. if ( l != ERROR_SUCCESS )
  92. {
  93. printf("Failed reading [WOWKEY]\\KnownDLLs\n");
  94. printf("Do you have administrator privleges?\n");
  95. exit(1);
  96. }
  97. if ( dwRegValueType != REG_SZ ) {
  98. printf("Internal error, [WOWKEY]\\KnownDLLs is not a REG_SZ (string)\n");
  99. exit(1);
  100. }
  101. printf("\nKey was: \"%s\"\n\n", sz );
  102. switch (argc)
  103. {
  104. case 1:
  105. FindOrAdd( sz, "compobj.dll" );
  106. FindOrAdd( sz, "storage.dll" );
  107. FindOrAdd( sz, "ole2.dll" );
  108. FindOrAdd( sz, "ole2disp.dll" );
  109. FindOrAdd( sz, "typelib.dll" );
  110. FindOrAdd( sz, "ole2nls.dll" );
  111. break;
  112. case 2:
  113. if( (strcmp(argv[1],"-r") == 0) ||
  114. (strcmp(argv[1],"/r") == 0))
  115. {
  116. FindAndDelete( sz, "compobj.dll" );
  117. FindAndDelete( sz, "storage.dll" );
  118. FindAndDelete( sz, "ole2.dll" );
  119. FindAndDelete( sz, "ole2disp.dll" );
  120. FindAndDelete( sz, "typelib.dll" );
  121. FindAndDelete( sz, "ole2nls.dll" );
  122. }
  123. else
  124. {
  125. printf("Unknown parameters\n");
  126. exit(1);
  127. }
  128. break;
  129. default:
  130. printf("Too many parameters\n");
  131. exit(1);
  132. }
  133. printf("Key is now: \"%s\"\n\n", sz );
  134. ulSize = strlen( sz );
  135. l = RegSetValueEx( WowKey,
  136. "KnownDLLs",
  137. 0,
  138. dwRegValueType,
  139. sz,
  140. ulSize+1 );
  141. if ( l != ERROR_SUCCESS ) {
  142. printf("Error setting value (l=%ld,0x%08lX)\n",l,l);
  143. printf("Do you have administrator privleges?\n");
  144. exit(1);
  145. }
  146. l = RegCloseKey( WowKey );
  147. return(0);
  148. }