PRB: Regsvr32 May Register COM In-Process Server from Different Directory (259012)



The information in this article applies to:

  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Professional
  • Microsoft Windows NT Advanced Server 4.0
  • Microsoft Windows NT Server 4.0

This article was previously published under Q259012

SYMPTOMS

If you have multiple copies of your Component Object Model (COM) dynamic-link library (DLL) in different folders, when you run Regsvr32 from the directory where the DLL is located, the Regsvr32 utility registers the DLL from different locations depending on which version of Microsoft Windows you are running. On Windows 2000-based computers, Regsvr32 registers the DLL from the directory where Regsvr32 resides. However, on Windows NT-based computers, Regsvr32 registers the DLL from the current directory.

For example:

  1. Regsvr32.exe is located in C:\WinNT\System32.Your ActiveX/COM DLL (Test.dll) is located in C:\WinNT\System32 and C:\MyProgram.Your current directory is C:\MyProgram.At a command prompt, type regsvr32 test.dll to register Test.dll.
  2. Your ActiveX/COM DLL (Test.dll) is located in C:\WinNT\System32 and C:\MyProgram.Your current directory is C:\MyProgram.At a command prompt, type regsvr32 test.dll to register Test.dll.
  3. Your current directory is C:\MyProgram.At a command prompt, type regsvr32 test.dll to register Test.dll.
  4. At a command prompt, type regsvr32 test.dll to register Test.dll.
On Windows 2000, Regsvr32 registers the DLL in C:\WinNT\System32. On Windows NT 4.0, Regsvr32 registers the DLL in C:\MyProgram.

CAUSE

To register a COM DLL, the Regsvr32 utility uses the following syntax with the LoadLibraryEx function:
LoadLibraryEx(lpFileName,NULL,LOAD_WITH_ALTERED_SEARCH_PATH)
				
If you pass a partial file name (that is, not a fully qualified path) to this function instead of using the altered search path strategy, LoadLibraryEx uses the standard search path strategy to load the DLL. The standard search path strategy searches for a file in the following sequence:

  1. The directory from which the application is loaded.The current directory.
  2. The current directory.
Thus, on Windows 2000, Regsvr32 registers the DLL in C:\Winnt\System32, which is the directory where Regsvr32 resides. However, on Windows NT 4.0, LoadLibraryEx does not enforce a fully qualified path while it uses LOAD_WITH_ALTERED_SEARCH_PATH because of a bug in LoadLibraryEx. Because a fully qualified path is not passed to the function, LoadLibraryEx does not know where the specified DLL is located and cannot start the search at "specified path". Thus, LoadLibraryEx starts the search at the current directory, and the DLL in the current directory is loaded.

RESOLUTION

To register the appropriate DLL in Windows 2000 and Windows NT, pass the fully qualified path of the DLL as a parameter to Regsvr32.

Modification Type:MajorLast Reviewed:5/12/2003
Keywords:kbInprocSvr kbnofix kbprb kbRegistry KB259012