WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE COM ADO CDO ADSI LDAP
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Trapping COM OLE Errors


Question:

How does one trap COM errors. If I run the following script twice, I get a OLE: Exception error. The script creates a printer port on a remote server. If I try to create the port twice I get the error. Also if I try to create a port without having the necessary permissions I get the same error. I know that the error should be access denied however I cannot seem to trap the COM errors. If I look in the WWWBATCH.ini I get the generic COM error 1621 as well.

Here is the script. (For it to work the PRNADMIN.DLL from the W2k Resource Supplement 1 needs to be registered)

Errormode(@Notify)
IntControl(73,2,0,0,0)
;Port types
kTcpRaw = 1
kTcpLPr = 2
kLocal = 3
kLocalDownLevel = 4
kLprMon = 5
kHPdlc = 7

oPort = CreateObject("Port.Port.1")
oMaster = CreateObject("PrintMaster.PrintMaster.1")
oPort.ServerName = "\\ececris1"
oPort.PortName = "XP_10.10.20.27"
oPort.PortType = kTcpRaw
oPort.HostAddress = "10.10.20.27"
oPort.PortNumber = "9100"
oMaster.PortAdd (oPort)
error= LastError()

MESSAGE ("All done","Complete !")
Errormode(@Cancel)
If I try to create the same port twice I get the error. The Vartype is 1537 or a comobject

THE VBS script that this is based on returns errors from an object called Hex(Err.Number) but when I try to use that in winbatch a=getobject(Err.Number) It returns an error "Object does not exist" ...

Answer:

You might try adding code to check if the port already exists. (Maybe using WMI or some other PrintMaster method).

Or try:

ErrorMode(@off)
oMaster.PortAdd(oPort)
ErrorMode(@cancel)
if LastError() == 1261 then
     Message("error","There was an error creating the port.")
	  exit
endif

User Reply:

Trapping error 1261 does not help because it is a generic error. This code is based on the PORTMGR.VBS script from the microsoft resource kit. If I run the script twice I get an error that the port already exists."Error: Adding port "IP_1.2.3.4", error: 0x80070034." Which roughly translates to the name already exists on the network. If I run it without enough permissions I get "Error: Adding port "IP_1.2.3.4", error: 0x80070005. Access is denied." I need to trap these errors. as for the error(@Notify) that was just some stuff left over from trying to make this thing work.

I need to be able to trap errors for any COM object. I am not that well versed in COM objects, is it possible that each .DLL my have its own error handling routines and this is why I cant trap them in Winbatch?

Answer:

Does that particular Object class expose an Error Object? If so post the documentation. No way that I am aware of to do general OLE error capturing in WinBatch.

User Reply:

There does not appear to be an error object. Here is some revelant information I have found however I am not a C++ or VB programer so I cannot make anything work. I dont know if this is any help.

The methods and properties of all interfaces return HRESULT codes. The PrintMaster object implements the ISupportErrorInfo interface in order to provide rich error information. Besides returning the HRESULT representing the error code of the action performed, all methods and properties of PrintMaster call FormatMessage and SetErrorInfo. This is to provide the scripting client with an error object that include a string description of the error.

If this were not the case, the scripting client wouldn't be always able to set a description for the error code returned by a method of an interface. This means for all interfaces other the IPrintMaster it is not guaranteed that Err.Description will contain a string (may be empty).

Answer:

Note: The ISupportErrorInfo interface is needed for early binding clients (WB is late binding) because they do not call the Invoke method.

The ISupportErrorInfo interface you are refering to is used to collect the same information we put in the additional info part of our error message boxes.

If you are running a current version: This information can be obtained using IntControl 73 for error handling. Upon error the variable 'wberroradditionalinfo' contains the same information the additional info part of our error message boxes.


Article ID:   W16561
File Created: 2005:02:18:12:21:28
Last Updated: 2005:02:18:12:21:28