INFO: OLE Server Launched by OLE Client Gets System Environment

Last reviewed: May 21, 1997
Article ID: Q149419

The information in this article applies to:
  • Microsoft OLE libraries - included with Microsoft Windows NT version 3.51

SUMMARY

An OLE server that is launched by an OLE client in Windows NT will get the SYSTEM environment and not the USER environment. This does not occur in Windows 95 where the SYSTEM environment and the USER environment are the same.

MORE INFORMATION

This behavior is by design and is because the OLE server is actually started by the OLE service. However this can cause the server to work differently when it is started by the user from the way it behaves when it is started by an OLE client. For example, if the server loads a DLL using LoadLibrary without the full path and the DLL is located in a directory in the USER path but not in the SYSTEM path, the DLL will be found when the server is run by the user but won't be found when the server is launched by an OLE client. Many applications do not run into this problem because they statically link to DLLs and those DLLs are in the same directory as the .exe file.

Many of the USER environment variables can be found as follows when the server is launched by OLE with the SYSTEM environment and this information can be used as a workaround to OLE's behavior:

The PATH, INCLUDE, TEMP, and LIB environment variables can be found by looking in the registry under HKEY_CURRENT_USER\Environment. USERNAME can by found using GetUserName(). HOMEDRIVE & HOMEPATH can be found using NetGetUserInfo as follows:

   USER_INFO_1 * pUserInfo;
   NetUserGetInfo (NULL, pszUserName, 1, (LPBYTE *)&puserinfo);
   The information will be returned in USER_INFO_1.usri1_home_dir.

OLE will also set the current working directory of the server to the SYSTEM32 directory when it launches it. The location of the server's .exe file can be found by using GetModuleFileName() in the server.

The server can determine if it was launched by OLE by looking for -Embedding or /Embedding in the command line arguments.

With Service Pack 3, local OLE servers on NT 4 that are set to start under the "Launching User" identity (the default setting,) will inherit the USER environment. Note that this does not apply to servers set to start under a "RunAs" identity (either Interactive User or a specific user). Also it does not apply to remote servers, only to local machine activations.

With this change, the default behavior for OLE servers (as far as inheriting environments is concerned) under NT4 becomes identical to that of Windows 95.

Keywords          : LeTwoArc kbinfo
Technology        : kbole
Version           : 3.51
Platform          : NT WINDOWS


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 21, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.