RegSvr32 exit codes documentation?

你离开我真会死。 提交于 2019-11-28 09:38:53
Ben

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

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.

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.

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://support.microsoft.com/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.

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!