$comval
Returns member value for the Nth instantiation of the enumerated collection in name.
$comval(name,N,member)
Dispatch and Unknown
The two variable types dispatch and unknown allow you to pass dispatch/unknown pointers as parameters in a $com() call, or retrieve dispatch/unknown pointers from a $com() call, by reference.
To pass a dispatch/unknown pointer as a parameter in $com(), specify the variable type as dispatch/unknown, and specify the name of an existing $com() connection as the value.
To retrieve a dispatch/unknown pointer through a call to $com(), specify a dispatch* item, with a variable name, as the last parameter in a $com() call, without assigning it a value. When $com() returns, mIRC will create a new $com() item with that variable name and assign it the dispatch or unknown pointer. See example script #2 below.
Note: In the case of retrieving an unknown pointer, mIRC will extend it to a dispatch pointer if it can, allowing you to call it directly via $com().
You can use $com().dispatch or $com().unknown to see if a pointer exists for that $com() item.
Example
The following script is a simple example that connects to excel and then retrieves and sets the visible property.
alias excel { comopen excel Excel.Application if ($comerr) { echo comopen failed halt } ; check if excel window is visible if ($com(excel,Visible,3) == 0) { echo $com failed goto finish } echo Visible: $com(excel).result ; make excel window visible if ($com(excel,Visible,5,i4,1) == 0) { echo $com failed goto finish } ; check visibility again if ($com(excel,Visible,3) == 0) { echo $com failed goto finish } echo Visible: $com(excel).result :finish comclose excel }
The following script retrieves information about your CPU. It displays debugging information so you can see whether a call succeeded or not, the value it returned, and whether a new COM object was created.
alias cpu { comopen Locator WbemScripting.SWbemLocator if ($comerr) { echo comopen failed | halt } echo com: $com(Locator, ConnectServer, 3, dispatch* Services) echo result: $com(Locator).result echo com(0): $com(0) if ($com(Services)) { echo com: $com(Services, Get, 3, string, Win32_Processor.DeviceID='CPU0', dispatch* More) echo result: $com(Services).result echo com(0): $com(0) if ($com(More)) { echo com: $com(More, Name, 3) echo result: $com(More).result echo com: $com(More, Caption, 3) echo result: $com(More).result echo com: $com(More, Manufacturer, 3) echo result: $com(More).result comclose More } comclose Services } comclose Locator }
The following script retrieves information about your hard drives. It does so by retrieving all drive instances in an enumerated collection and then accessing member values for each instance using the $comval() identifier.
alias drives { comopen Locator WbemScripting.SWbemLocator if ($comerr) { echo comopen failed | halt } echo Com: $com(Locator,ConnectServer,3, dispatch* Services) echo Result: $com(Locator).result comclose Locator if $com(Services) { echo com: $com(Services, InstancesOf,3,string,Win32_LogicalDisk,dispatch* Instances) echo result: $com(Services).result comclose Services } if $com(Instances) { echo com: $com(Instances,Count,3) var %n = $com(Instances).result echo result: %n var %m = 1 while (%m <= %n) { echo 4 disk: %m echo 3 Com: $comval(Instances, %m, Name) echo 3 Com: $comval(Instances, %m, FileSystem) echo 3 Com: $comval(Instances, %m, FreeSpace) echo 3 Com: $comval(Instances, %m, Description) inc %m } comclose instances } }
See Also
- COM Objects for /comopen /comclose /comlist /comreg $comerr