“System.Exception: 无法创建 ActiveX 组件”之后

本文介绍了解决IIS6.0环境下运行含有Excel自动化操作的页面时出现的“无法创建ActiveX组件”错误的方法。通过安装Office、配置DCOM权限等步骤,使IIS能够成功创建Excel进程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一台新的WIN2K3机器,IIS6.0。在运行一个使用到EXCEL自动化的页面时,出现了以下的错误。

Select Distinct WSN from VBApplication.dbo.WF_LIFactView where WS = 'ACC08EAE-D161-4DD7-A166-6DA76630600F';Select * from VBApplication.dbo.WF_LIFactView where WS = 'ACC08EAE-D161-4DD7-A166-6DA76630600F' and LI = '%'and [Year] = 2006 and [Month] = 1System.Exception: 无法创建 ActiveX 组件。 在 Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName) 在 ASP.report_wf_lireport_aspx.Page_Load(Object sender, EventArgs e) 位置 D:/PortalXP/Report/WF/LIReport.aspx:行号 67路径不能为空。参数名: path  

其实这个错误是由于IIS账户没有创建EXCEL进程实例引起的,只要做以下的步骤就可以了。

1、安装Office

2、在开始-》运行中打入dcomcnfg.exe,启动组件服务。

3、在组件服务中,选择控制台根目录-》组件服务-》计算机-》我的电脑-》DCOM配置-》Microsoft Excel应用程序,右击属性,打开属性窗口。

4、在安全页签中,对配置启动和激活权限进行自定义,加入启动IIS进程帐户的完全权限。

import com.jacob.activeX.ActiveXComponent; import com.jacob.com.Dispatch; import java.lang.reflect.Field; public class ZKTecoConnectionExample { static { // 设置java.library.path System.setProperty("java.library.path", "D:\\jacob-1.19"); // 重新加载java.library.path(因为System.setProperty不会立即生效) try { Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths"); fieldSysPath.setAccessible(true); fieldSysPath.set(null, null); } catch (Exception e) { e.printStackTrace(); } // 加载jacob库 System.load("D:/jacob-1.19/jacob-1.19-x64.dll"); // 确保文件名与实际文件名一致 } public static void main(String[] args) { try { // 创建 ActiveX 组件 ActiveXComponent zkem = new ActiveXComponent("zkemkeeper.ZKEM"); // 考勤机的 IP 地址和端口 String ip = "192.168.13.14"; // 替换为考勤机的实际 IP 地址 int port = 4370; // 默认端口 // 尝试连接考勤机 boolean isConnected = Dispatch.call(zkem, "Connect_Net", ip, port).getBoolean(); if (isConnected) { System.out.println("Connected to device."); // 尝试使用默认密码 int[] defaultPasswords = {0, 0, 0, 0, 0, 0}; // 默认密码 boolean isAuth = false; for (int password : defaultPasswords) { isAuth = Dispatch.call(zkem, "SetCommPassword", password).getBoolean(); if (isAuth) { System.out.println("Authentication successful with password: " + password); break; } } if (isAuth) { // 读取用户信息 boolean isRead = Dispatch.call(zkem, "ReadAllUserID", 1).getBoolean(); // 1 表示从设备读取 if (isRead) { System.out.println("User data read successfully."); } else { System.out.println("Failed to read user data."); } } else { System.out.println("Authentication failed. Please check the password."); } // 断开连接 Dispatch.call(zkem, "Disconnect"); } else { System.out.println("Failed to connect to device."); } } catch (Exception e) { e.printStackTrace(); } } }运行结果com.jacob.com.ComFailException: Can't co-create object at com.jacob.com.Dispatch.createInstanceNative(Native Method) at com.jacob.com.Dispatch.<init>(Dispatch.java:99) at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58) at ZKTecoConnectionExample.main(ZKTecoConnectionExample.java:27)
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值