DCOM简单示例(03)

本篇文章介绍了如何写一个简单的DCOM客户端(VBS)。

1、testDCOM.vbs

'发生错误时,继续运行
On Error Resume Next

'清除错误状态
Err.Clear

'本地调用
'Set Obj=CreateObject("ATLExe.JustATestExe")
'Set Obj=CreateObject("ATLExe.JustATestExe.1")
'远程调用
Set Obj=CreateObject("ATLExe.JustATestExe","127.0.0.1")
'Set Obj=CreateObject("ATLExe.JustATestExe.1","127.0.0.1")

'输出错误信息
If Err.Number <> 0 Then
    WScript.Echo "Error: " & Err.Number
    WScript.Echo "Error (Hex): " & Hex(Err.Number)
    WScript.Echo "Source: " &  Err.Source
    WScript.Echo "Description: " &  Err.Description
    'Err.Clear
    '退出程序
    WScript.Quit(Err.Number)
End If

'On Error Goto 0

WScript.Echo obj.Add(1,2)
WScript.Echo obj.SayHiTo("dcom")

set obj=Nothing

2、运行

cscript testDCOM.vbs

3、如果是本机测试,一般不会遇到权限问题,但如果是远程测试的话,要先进行配置的,我之前写过这样的文章,打开可以参考一下。

Leave a Reply

Your email address will not be published. Required fields are marked *

*