以下建议适用于在
vbscript jscript vba中使用
Server.CreateObject
和
CreateObject
。
Web服务器部分是针对
asp-classic的,但仍值得一读。
什么导致了这个错误?
Server.CreateObject 失败
通常情况下,当 Web 应用程序在没有理解使用外部 COM 组件并在 Web 服务器上注册的情况下从一个 Web 服务器移动到另一个 Web 服务器时,会出现此错误。
来自 PRB: Server.CreateObject Returns HTTP 500.100 or ASP 0177 Error (0x8007007E)
当您尝试使用 Server.CreateObject 方法实例化未在本地系统上注册的对象时,会出现此错误。
确定错误来源
如果您在 ASP Web 应用程序中使用 COM 组件,则会看到类似于以下行:
set g_pcmsrv=Server.CreateObject("PCMServer.PCMServer")
通常错误会指向
Set
行,这使得识别原因更容易
(幸运的是你已经有一些很好的跟踪代码了,所以更好)。
如果您不知道DLL位于何处怎么办?
注意: 访问Windows注册表时请小心,因为很容易无意中进行更改,这对操作系统产生严重后果,在极端情况下需要系统还原或重新安装/修复。
CreateObject
方法内的字符串称为ProgId
,用作标识符,指向Windows注册表中的一个键,可以在其中找到该键
注意: 在大多数Windows版本中,可以使用regedit.exe
(也称为注册表编辑器)浏览Windows注册表。使用此工具浏览Windows注册表时要非常小心。
HKEY_CLASSES_ROOT
并且通过扩展
HKEY_LOCAL_MACHINE\Classes
每当ASP处理器遇到一个
ProgId
时,它会尝试访问Windows注册表并查找相应的键,以确定已注册的COM可访问DLL的位置。
HKEY_CLASSES_ROOT\PCMServer.PCMServer
一种常见的方法是,关键字包含一个名为
CLSID
的子键,它指向与注册的DLL相关联的类GUID。一旦在注册表中找到GUID关键字,
HKEY_CLASSES_ROOT\CLSID
使用Hive查找子键位置
Hive可以通过查找子键来找到位置。
HKEY_CLASSES_ROOT\CLSID\{GUID from CLSID}\InprocServer32
位置将存储在(默认)
值中。
Example Using the ProgId
- Scripting.FileSystemObject
Locate Scripting.FileSystemObject
subkey in HKEY_CLASSES_ROOT
HKEY_CLASSES_ROOT\Scripting.FilesystemObject
Identify GUID from subkey CLSID
HKEY_CLASSES_ROOT\Scripting.FilesystemObject\CLSID
(default) - "{0D43FE01-F093-11CF-8940-00A0C9054228}"
Use GUID to find registered DLL subkey in HKEY_CLASSES_ROOT\CLSID
HKEY_CLASSES_ROOT\CLSID\{0D43FE01-F093-11CF-8940-00A0C9054228}
Check subkey InprocServer32
(default)
value for the DLL location
HKEY_CLASSES_ROOT\CLSID\{0D43FE01-F093-11CF-8940-00A0C9054228}\InprocServer32
(default) - "C:\Windows\System32\scrrun.dll"
注册表中没有PCMServer.PCMServer
的ProgId
?
如果您在注册表中找不到相应的ProgId
,可能是由于以下两个原因之一:
- DLL未注册。
- DLL已在错误的区域注册。
如何在Windows中注册COM DLL
可以通过使用具有提升权限的Windows命令提示符中的regsvr32.exe
工具来注册COM DLL并创建相应的注册表条目(这因Windows版本而异)。
但在继续之前,操作系统的架构和ASP Web应用程序使用的模式非常重要。
大多数新硬件都是64位的,这在Windows中产生了一个难题,因为它现在必须支持更新的64位架构,同时仍然支持32位架构。微软想出的解决方案是将操作系统分成两个部分,所以我们有64位元素和32位元素。主要的操作系统程序被分解成两个文件夹
(只有在64位操作系统上才有,因为32位操作系统不必处理64位,即使硬件有能力)。
注意: 在仅有32位的系统上,只需使用64位位置来存储系统文件和Windows注册表。
在64位操作系统上,系统程序位于
For 64 Bit programs
%SystemRoot%\System32\
For 32 Bit programs
%SystemRoot%\SysWOW64\
这也适用于Windows注册表。
64 Bit
HKEY_CLASSES_ROOT
32 Bit
HKEY_CLASSES_ROOT\Wow6432Node
例如,在 Windows 的 64 位版本中,以下命令将在 32 位注册表中注册 PCMSRV32.DLL 并创建相关的 COM DLL 注册表键。
C:\Windows\SysWOW64>regsvr32 "C:\Windows\PCMSRV32.DLL"
IIS应用程序池
随着所有东西都开始支持64位,包括IIS,您仍然需要支持只支持32位COM的旧应用程序,因此在IIS 6.0中引入了应用程序池设置下的可配置属性Enabled32BitAppOnWin64
(从Windows Server 2003 Service Pack 1开始)。该属性允许应用程序池在64位Windows上以32位模式运行。
因此,在注册COM DLL之前,您需要知道应用程序池是否在32位模式下运行。在IIS 7.0及以上版本中,您可以在IIS管理器应用程序中的应用程序池属性中检查此设置。该设置在“常规”部分下的“高级设置”中,称为“启用32位应用程序”(也可以在<ApplicationPools>
部分下使用enable32BitAppOnWin64
在applicationHost.config
中进行配置)。
If Enable 32-Bit Applications
is set to False
The IIS Application Pool is running in native 64 Bit mode and any COM DLLs that need to be used by the ASP Web Application will need to support 64 Bit and be registered using the 64 Bit version of regsvr32.exe
to be added into the 64 Bit registry.
C:\Windows\System32>regsvr32 "C:\Windows\PCMSRV32.DLL"
If Enable 32-Bit Applications
is set to True
The IIS Application Pool is running in 32 Bit Mode and any COM DLLs that need to be used by the ASP Web Application will need to be 32 Bit COM DLLs and be registered using the 32 Bit version of regsvr32.exe
to be added into the 32 Bit registry.
C:\Windows\SysWOW64>regsvr32 "C:\Windows\PCMSRV32.DLL"
使用错误版本的 regsvr32.exe
注册 COM DLL
例如,使用:
C:\Windows\SysWOW64>regsvr32 "C:\Windows\PCMSRV32.DLL"
在64位Windows版本中,当IIS应用程序池不处于32位模式时,将COM DLL注册到32位注册表中会导致ASP 500.100
内部服务器错误。
服务器对象错误 'ASP 0177: 8007007e'
Server.CreateObject 失败
COM DLL清单
What is the IIS Application Pool Advanced Setting Enable 32-Bit Applications
set to, as it impacts on how you register the COM DLL?
Is the DLL registered using the architecture-specific version of regsvr32.exe
(if Windows version isn't 64 Bit use the default) that reflects the setting of Enable 32-Bit Applications
?
Does the Windows Registry contain a ProgId
for the DLL in the architecture-specific location of
HKEY_CLASSES_ROOT
that reflects the setting of Enable 32-Bit Applications
?
Does the InprocServer32
key contain the correct location for the DLL?
In the context of the account I'm using to access the COM DLL (ApplicationIdentity, LocalSystem, NetworkService etc), do I have permission to access both the physical DLL file and the registry entries?
有用的链接
regsvr32 dllname
注册,还要记得在多种架构环境中使用正确的版本。例如,如果 IIS Web 应用程序池以 32 位模式运行,则需要使用 32 位regsvr32
注册 DLL。 - user692942