Microsoft KB Archive/149419

= INFO: OLE Server Launched by OLE Client Gets System Environment =

Article ID: 149419

Article Last Modified on 10/15/2003

-

APPLIES TO


 * Microsoft OLE 4.0, when used with:
 * Microsoft Windows NT 3.51 Service Pack 5

-



This article was previously published under Q149419



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: kbserver KB149419

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.