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.

132 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. midware.c
  5. Abstract:
  6. Setting OEM default middleware application settings.
  7. This is a separate .c file because the linker pulls in an entire OBJ file
  8. if any function in the OBJ file is called.
  9. (1) This file contains static data which we don't want pulled into a
  10. host application unless the application actually calls
  11. SetDefaultOEMApps().
  12. (2) The host application is expected to implement the function
  13. ReportSetDefaultOEMAppsError(). By keeping it in a separate
  14. OBJ, only host applications that call SetDefaultOEMApps()
  15. need to define ReportSetDefaultOEMAppsError().
  16. --*/
  17. #include <pch.h>
  18. #include <winbom.h>
  19. BOOL SetDefaultAppForType(LPCTSTR pszWinBOMPath, LPCTSTR pszType, LPCTSTR pszIniVar)
  20. {
  21. TCHAR szBuf[MAX_PATH];
  22. TCHAR szDefault[MAX_PATH];
  23. HKEY hkType;
  24. BOOL fOEMAppSeen = FALSE;
  25. if (!pszWinBOMPath[0] ||
  26. !GetPrivateProfileString(INI_SEC_WBOM_SHELL, pszIniVar, NULLSTR,
  27. szDefault, ARRAYSIZE(szDefault),
  28. pszWinBOMPath))
  29. {
  30. // OEM didn't specify an app, so act as if we "saw" it
  31. // so we don't complain that the OEM specified an app that
  32. // isn't installed.
  33. fOEMAppSeen = TRUE;
  34. }
  35. wnsprintf(szBuf, ARRAYSIZE(szBuf), _T("Software\\Clients\\%s"), pszType);
  36. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szBuf, 0,
  37. KEY_READ | KEY_WRITE, &hkType) == ERROR_SUCCESS)
  38. {
  39. DWORD dwIndex;
  40. for (dwIndex = 0;
  41. RegEnumKey(hkType, dwIndex, szBuf, ARRAYSIZE(szBuf)) == ERROR_SUCCESS;
  42. dwIndex++)
  43. {
  44. HKEY hkInfo;
  45. BOOL fIsOEMApp = lstrcmpi(szBuf, szDefault) == 0;
  46. StrCatBuff(szBuf, _T("\\InstallInfo"), ARRAYSIZE(szBuf));
  47. if (RegOpenKeyEx(hkType, szBuf, 0, KEY_READ | KEY_WRITE, &hkInfo) == ERROR_SUCCESS)
  48. {
  49. DWORD dw, dwType, cb;
  50. if (fIsOEMApp)
  51. {
  52. // Set this as the OEM default app
  53. dw = 1;
  54. RegSetValueEx(hkInfo, _T("OEMDefault"), 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw));
  55. // If it's the default app, then ARP will show the icon automatically
  56. RegDeleteValue(hkInfo, _T("OEMShowIcons"));
  57. fOEMAppSeen = TRUE;
  58. }
  59. else
  60. {
  61. // If it's not the OEM default app then untag it
  62. RegDeleteValue(hkInfo, _T("OEMDefault"));
  63. // and copy the current icon show state to the OEM show state
  64. // (or delete the OEM show state if no show info is available)
  65. cb = sizeof(dw);
  66. if (RegQueryValueEx(hkInfo, _T("IconsVisible"), NULL, &dwType, (LPBYTE)&dw, &cb) == ERROR_SUCCESS &&
  67. dwType == REG_DWORD && (dw == TRUE || dw == FALSE))
  68. {
  69. RegSetValueEx(hkInfo, _T("OEMShowIcons"), 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw));
  70. }
  71. else
  72. {
  73. RegDeleteValue(hkInfo, _T("OEMShowIcons"));
  74. }
  75. }
  76. RegCloseKey(hkInfo);
  77. }
  78. }
  79. RegCloseKey(hkType);
  80. }
  81. if (!fOEMAppSeen)
  82. {
  83. ReportSetDefaultOEMAppsError(szDefault, pszIniVar);
  84. }
  85. return fOEMAppSeen;
  86. }
  87. typedef struct {
  88. LPCTSTR pszKey;
  89. LPCTSTR pszIni;
  90. } DEFAULTAPPINFO;
  91. const DEFAULTAPPINFO c_dai[] = {
  92. { _T("StartMenuInternet") ,INI_KEY_WBOM_SHELL_DEFWEB },
  93. { _T("Mail") ,INI_KEY_WBOM_SHELL_DEFMAIL },
  94. { _T("Media") ,INI_KEY_WBOM_SHELL_DEFMEDIA },
  95. { _T("IM") ,INI_KEY_WBOM_SHELL_DEFIM },
  96. { _T("JavaVM") ,INI_KEY_WBOM_SHELL_DEFJAVAVM },
  97. };
  98. BOOL SetDefaultOEMApps(LPCTSTR pszWinBOMPath)
  99. {
  100. BOOL fRc = TRUE;
  101. int i;
  102. for (i = 0; i < ARRAYSIZE(c_dai); i++)
  103. {
  104. if (!SetDefaultAppForType(pszWinBOMPath, c_dai[i].pszKey, c_dai[i].pszIni))
  105. {
  106. fRc = FALSE;
  107. }
  108. }
  109. return fRc;
  110. }