Comopen: Difference between revisions

From Scriptwiki
Jump to navigation Jump to search
Added $comerr and /COMREG to the same page.
Line 1: Line 1:
This opens a COM connection to object progid eg. Excel.Application, and assigns the connection a name.
This opens a COM connection to object progid eg. Excel.Application, and assigns the connection a name.
  /comopen name progid
  /comopen name progid


You should check [[$comerr]] after making this call to confirm that the COM connection was successful.
'''$comerr''' checked after a call to any COM command or identifier. Returns 1 if there was an error, 0 otherwise.


== COMLIST and COMCLOSE ==
== /COMCLOSE ==
Use /comclose to close the COM connection.
/comclose name
 
== /COMLIST ==
Use /comlist to list all open COM connections.
Use /comlist to list all open COM connections.
  /comlist
  /comlist


Use /comclose to close the COM connection.
== /COMREG ==
  /comclose name
/comreg -u filename
 
This registers/unregisters a COM DLL with windows.
 
'''Example'''
  alias comRegister {
  comopen name progid
  ; if comopen failed, maybe the DLL that came with the script is not registered
  if ($comerr) {
 
    ;register the DLL
    comreg test.dll
 
    ;try to open it again
    comopen name progid


== See Also ==
    ; still failed, halt the script
* [[$comerr]]
    if ($comerr) halt
  }
}

Revision as of 20:29, 6 July 2014

This opens a COM connection to object progid eg. Excel.Application, and assigns the connection a name.

/comopen name progid

$comerr checked after a call to any COM command or identifier. Returns 1 if there was an error, 0 otherwise.

/COMCLOSE

Use /comclose to close the COM connection.

/comclose name

/COMLIST

Use /comlist to list all open COM connections.

/comlist

/COMREG

/comreg -u filename

This registers/unregisters a COM DLL with windows.

Example
alias comRegister {
  comopen name progid

  ; if comopen failed, maybe the DLL that came with the script is not registered
  if ($comerr) {
    ;register the DLL
    comreg test.dll
    ;try to open it again
    comopen name progid
    ; still failed, halt the script
    if ($comerr) halt
  }
}