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.

111 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. SetEnvironmentVariable.cpp
  5. Abstract:
  6. mapi dlls don't ship with w2k, and with outlook2000 it gets installed in a different
  7. location (%commonprogramfiles%)
  8. resumemaker and possibly others depend on mapi dlls being in system32 directory.
  9. Command line syntax is "envvariablename|envvariablevalue|envvariablename|envvariablevalue"
  10. Notes:
  11. This is an app specific shim.
  12. History:
  13. 07/02/2000 jarbats Created
  14. --*/
  15. #include "precomp.h"
  16. IMPLEMENT_SHIM_BEGIN(SetEnvironmentVariable)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_END
  20. /*++
  21. Set environment variables in the command line to get some dll path resolutions correct.
  22. --*/
  23. BOOL
  24. NOTIFY_FUNCTION(
  25. DWORD fdwReason
  26. )
  27. {
  28. if (fdwReason == DLL_PROCESS_ATTACH) {
  29. char *CmdLine = COMMAND_LINE;
  30. char *lpstrEnvName;
  31. char *lpstrEnvVal;
  32. for (;;)
  33. {
  34. lpstrEnvName = lpstrEnvVal = CmdLine;
  35. while (*CmdLine && (*CmdLine != '|')) CmdLine++;
  36. if (*CmdLine == '|')
  37. {
  38. *CmdLine = '\0';
  39. CmdLine++;
  40. }
  41. lpstrEnvVal = CmdLine;
  42. if (0 == *lpstrEnvVal)
  43. {
  44. break;
  45. }
  46. CSTRING_TRY
  47. {
  48. CString csEnvValue(lpstrEnvVal);
  49. if (csEnvValue.ExpandEnvironmentStringsW() > 0)
  50. {
  51. if (SetEnvironmentVariableA(lpstrEnvName, csEnvValue.GetAnsi()))
  52. {
  53. DPFN( eDbgLevelInfo, "Set %s to %s\n", lpstrEnvName, csEnvValue.GetAnsi());
  54. }
  55. else
  56. {
  57. DPFN( eDbgLevelInfo, "No Success setting %s to %s\n", lpstrEnvName, lpstrEnvVal);
  58. }
  59. }
  60. }
  61. CSTRING_CATCH
  62. {
  63. // Do nothing
  64. }
  65. while (*CmdLine && (*CmdLine == '|')) CmdLine++;
  66. }
  67. }
  68. return TRUE;
  69. }
  70. /*++
  71. Register hooked functions
  72. --*/
  73. HOOK_BEGIN
  74. CALL_NOTIFY_FUNCTION
  75. HOOK_END
  76. IMPLEMENT_SHIM_END