What do the various regsvr32 exit codes mean?

Date:September 20, 2018 / year-entry #214
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20180920-00/?p=99785
Comments:    9
Summary:Reporting which step the problem occurred at.

The exit codes for the regsvr32 program are currently as follows:

Exit code Meaning
0 Success
1 Error parsing command line
2 OleInitialize failed
3 LoadLibrary failed
4 GetProcAddress failed
5 Registration function failed

This information is included for diagnostic and troubleshooting purposes. I don't think the values are contractual.

The regsvr32 program basically does five things, and the exit codes correspond to each of those steps.

  1. Parse the command line to see what it's being asked to do.
  2. Initialize OLE.
  3. Load the library.
  4. Find the function to be called. The command line options specify which function to look for. Could be Dll­Register­Server, Dll­Unregister­Server, or even Dll­Install.
  5. Call it.

Steps 4 and 5 may be repeated if the command line options indicate that multiple functions should be called.

If something goes wrong, the regsvr32 program reports the error details to the user, and the exit code summarizes which step it got stuck at. Future versions of regsvr32 may add additional steps, or change the order of the steps, which would trigger renumbering. The exit code is for diagnostic and troubleshooting purposes, so you can try to figure out why something went wrong.

We'll put this information to use next time.


Comments (11)
  1. I always believed the 5 was an ERROR_ACCESS_DENIED getting passed through. Interesting.

  2. Remy Lebeau says:

    Why not update the official documentation to include the exit codes and make them contractual?

    https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/regsvr32#BKMK_examples

    1. Then it would be impossible to add new exit codes.

      1. DWalker07 says:

        No, you would just have to document the new ones.

        1. That would be a breaking change. “We wrote a program that checks the return value and assumes that code 3 means that LoadLibrary failed. But you introduced a new return value 6 that means “LoadLibrary failed because the DLL is not signed.” This is a bug. That situation should be reported as code 3, because that’s how you documented it. You can’t make breaking changes like this. Our product relies on the error codes as they were documented.”

  3. jon says:

    Maybe future versions could elevate if necessary, to save me having to remember I need an elevated command prompt.

    1. But then you wouldn’t be able to run it silently. It would display an elevation prompt and hang your batch file.

    1. If the DLL being registered returns an error, that error code is reported on the screen, but regsvr32 exits with code 5 (“DLL explicitly failed registration”).

  4. Doesn’t regsvr32.exe (step 3a) launch its sister version of another bitness if the 32 bit version of regsvr32.exe is asked to register a 64 bit dll (and vice versa)?

  5. Those return codes were hinted at the now deleted KB207132 (formerly Q207132) article from Microsoft Support, titled “INFO: How Regsvr32.exe Registers and Unregisters COM DLLs”. An archived copy can be recovered from the Wayback Machine, but the sample code appears garbled because the line returns are missing. An even older copy can be located elsewhere and a more elaborated code sample is found in the Visual C++ Samples repository. However, that doesn’t mean any connection to the official Regsvr tool, obviously!

    https://web.archive.org/web/20161219202259/support.microsoft.com/en-us/kb/207132
    https://github.com/Microsoft/VCSamples/blob/master/VC2010Samples/MFC/controls/regsvr/regsvr.cpp

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index