Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegSvr32 exit codes documentation?

I played with RegSvr32.exe to register a COM Server and got next exit codes:

0 - when registering properly normal DLL Com Server

3 - when try registering fake DLL Com Server (simple text file renamed to .DLL

4 - when try registering simple DLL, not Com Server

Question: where I can find official (or non-official but good) description of all possible exit codes and their meaning?

Search on internet didn't give me result, on SO I found this topic where is written that exit codes are the same with windows system error code, but I didn't understand why then when try registering bad file I am obtaining code = 3 = ERROR_PATH_NOT_FOUND, and when registering non-COM DLL - 4 = ERROR_TOO_MANY_OPEN_FILES? For me it doesn't sound logically.

like image 1000
ALZ Avatar asked Feb 28 '14 11:02

ALZ


People also ask

How do I register Regsvr32 on Windows 10?

Click Start > All Programs > Accessories and right-click on "Command Prompt" and select "Run as Administrator" OR in the Search box, type CMD and when cmd.exe appears in your results, right-click on cmd.exe and select "Run as administrator" At the command prompt, enter: REGSVR32 "PATH TO THE DLL FILE"

How do I manually register a DLL?

Register 32 or 64-bit DLLs in Windows Step 1: First click on Start, then Run. Step 2: Now all you have to do to register a DLL file is to type in the regsvr32 command, followed by the path of the DLL file. Step 3: Now click OK and you should get a confirmation message that the DLL has been registered successfully.


3 Answers

The exit codes are not documented. The documentation is here:

  • https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/regsvr32

However, the source code for a version REGSVR32.EXE is shipped with Visual Studio 2008. This gives its version as 4.0.0, so is not the same as the one shipped with windows, which reports version 6.

  • http://msdn.microsoft.com/en-us/library/ms177531(v=vs.90).aspx

A quick look shows these:

#define FAIL_ARGS   1 // Invalid Argument
#define FAIL_OLE    2 // OleInitialize Failed
#define FAIL_LOAD   3 // LoadLibrary Failed
#define FAIL_ENTRY  4 // GetProcAddress failed
#define FAIL_REG    5 // DllRegisterServer or DllUnregisterServer failed.

Reading the source code suggests that under no circumstances does it return any other code than the ones above and zero for success, which proves it isn't the same as the Windows one.

I suspect that the difference in return codes is if it gets as far as GetProcAddress, it then returns the exit code from the function it calls, instead of just always returning 5.

Ideally they would have made it use GetLastError to get a more useful exit code, but I suspect there are too many tools (e.g. third party install programs) which now depend on exit codes 2-4, and it is too late to change it.

Also see What do the various regsvr32 exit codes mean? on Raymond Chen's blog on MSDN.

like image 139
Ben Avatar answered Oct 08 '22 14:10

Ben


Visual Studio used to ship with a MFC sample that was actually the source for the RegSvr32 utility and I remember going through that to harvest the exit codes:

FAIL_ARGS   1
FAIL_OLE    2
FAIL_LOAD   3
FAIL_ENTRY  4  // Not ERROR_TOO_MANY_OPEN_FILES but as expected "could not resolve 
               // DLLRegisterServer" as your using an invalid DLL
FAIL_REG    5

I can't find the sample, but if I Google for what I extracted there is this: http://web.archive.org/web/20140803013714/http://support.microsoft.com:80/kb/207132 which has matching codes so it looks like that KB demo code was also taken from RegSvr. Its trivial to work out the reasons behind each of the failure codes.

like image 28
Alex K. Avatar answered Oct 08 '22 13:10

Alex K.


Ben's answer is correct, though, do take note that error code 3 is also given as a result if

  • the .DLL could not be found
  • the .DLL was locked by another process and could not be read
  • the process had insufficient rights to open the file. Eg, not running with admin rights when needed (with specific files or common files on the C drive)

> #define FAIL_LOAD 3 // LoadLibrary Failed

Feels a little bit vague, but the LoadLibrary is meant as DLLs referred within the specific DLL. Using an application such as Depends, you can find all references, including missing ones. Take note that a missing reference does not always result an error code 3 (in cases where the DLL actually didn't use it)

like image 5
Biepbot Von Stirling Avatar answered Oct 08 '22 13:10

Biepbot Von Stirling