COMate - control COM objects via automation - OBSOLETE!
If you ask COMate to retrieve a string property when in fact it encounters an integer property then it simply converts it to a string etc.
Last edited by srod on Fri Sep 26, 2008 10:35 pm, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
Hi Srod,
I have spend some time at this methode, and found Out that
for set the value with the methode enablestatic is needed to generate a "new Instance of the class" using spawninstance_()
I have give a look on the example and try some possibility with comate
but this was not really succesfully.
here a vbs script that demostrate this other way:
Hope that you can point me on the right direction.
Thanks
jpd
I have spend some time at this methode, and found Out that
for set the value with the methode enablestatic is needed to generate a "new Instance of the class" using spawninstance_()
I have give a look on the example and try some possibility with comate
but this was not really succesfully.
here a vbs script that demostrate this other way:
Code: Select all
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
' Obtain an instance of the the class
' using a key property value.
Set objShare = objWMIService.Get("Win32_NetworkAdapterConfiguration.Index='4'")
' Obtain an InParameters object specific
' to the method.
Set objInParam = objShare.Methods_("EnableStatic"). _
inParameters.SpawnInstance_()
' Add the input parameters.
objInParam.Properties_.Item("IPAddress") = "192.168.110.1"
objInParam.Properties_.Item("SubnetMask") = "255.255.255.0"
' Execute the method and obtain the return status.
' The OutParameters object in objOutParams
' is created by the provider.
Set objOutParams = objWMIService.ExecMethod("Win32_NetworkAdapterConfiguration.Index='4'", "EnableStatic", objInParam)
' List OutParams
Wscript.Echo "Out Parameters: "
Wscript.echo "ReturnValue: " & objOutParams.ReturnValue
Thanks
jpd
PB 5.10 Windows 7 x64 SP1
jpd;
maybe something like this using the Invoke of Comate ? I haven't tried it yet but maybe, I just threw it together real quick at 4:30 this morning when I read your post. I don't think that you need the array thing for this method actually:
There are actually two different index's that do the same thing. The interface index and the LUID index from the registry. They are different from each other. The inteface index is from the IPv4 routing table and might be 8 while the LUID index is from the registry and might be for example 4. Both ID the particular adapter.
The wmi script from the MSDN looks like this:
if you set a static IP you also need to set the gateway and the gateway metric. Windows usually takes care of the the gateway metric for you if you set the static thru the GUI, but I think if you set it thru WMI you also need to set the metric.
maybe something like this using the Invoke of Comate ? I haven't tried it yet but maybe, I just threw it together real quick at 4:30 this morning when I read your post. I don't think that you need the array thing for this method actually:
Code: Select all
XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pbi"
Define.COMateObject objWMIService, Adapter
colAdapters.COMateEnumObject
strComputer.s = "."
;Interface_Index.s = "the route table Interface Index" ; works for Win Vista only
Index.s = "the LUID index from the registry" ; works with winXP and Win Vista
IP_Address_to_Set_and_subnet_mask.s = "Your Static IP address here , sub_net_mask "
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
;colAdapters = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_NetworkAdapterConfiguration Where InterfaceIndex= $0027" + Interface_Index +"$0027')") ; win Vista only
colAdapters = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_NetworkAdapterConfiguration Where Index= $0027" + Index.s +"$0027')") ; winXP and Win Vista
If colAdapters
Adapter= colAdapters\GetNextObject()
While Adapter
Adapter\Invoke("EnableStatic, $0027" + IP_Address_to_Set_and_subnet_mask + " $0027)
Adapter\Release()
Adapter = colAdapters\GetNextObject()
Wend
colAdapters\Release()
EndIf
objWMIService\Release()
EndIf
The wmi script from the MSDN looks like this:
Code: Select all
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration " _
& "where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.141")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.100")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic( _
strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(_
strGateway, strGatewaymetric)
Next
Ok, Thanks.Srod wrote: Sorry, I have no experience with such stuff and lack the time right now.
Yes I use it on all possible combination, as simple string with arrays,SFSxOI wrote: maybe something like this using the Invoke of Comate ?
savearray ...
but in all cases this error appair:
-2147024809
One or more arguments are invalid. Possibly a numerical overflow or too many nested objects, -if so, try splitting your method call into two or more subcalls.
on this error I read alway try splitting and with the wmi code creator tool
on execute methode, was generated the code posted yesterday...
the problem is that I cannot see a possibility with COMate to
try the following line:
Code: Select all
Set objInParam = objShare.Methods_("EnableStatic"). _
inParameters.SpawnInstance_()
Thanks
jpd
PB 5.10 Windows 7 x64 SP1
Code: Select all
objInParam.COMateObject = objShare\GetObjectProperty("Methods_('EnableStatic')\inParameters\SpawnInstance_()")
As for your safe-arrays you must remember to embed them within variants before passing them etc.
I may look like a mule, but I'm not a complete ass.
Problem with variant array
here is my code which works with pure displayhelper
This instruction cause an error
oDoc = oDesk\GetObjectProperty("loadComponentFromURL('"+file+"' , '_blank', 0, " + Str(openarray) + " as variant)")
May someone can help me.
Code: Select all
;EnableExplicit
;'Les objets de base pour travailler avec OOo
Declare MakePropertyValue(cName.s, uValue.b)
Declare MakePropertyValue1(cName.s, uValue.s)
Declare.s ConvertToUrl(strFile.s)
IncludePath ".\"
XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"
Define mafeuille,lesfeuille
Define.COMateObject oSM,oDesk,oDoc
Define.safearray *openpar
Define.variant openarray
*openpar = saCreateSafeArray(#VT_DISPATCH, 0, 3)
SA_DISPATCH(*openpar, 0) = MakePropertyValue("ReadOnly", #True)
SA_DISPATCH(*openpar, 1) = MakePropertyValue1("Password", "ISABELLE")
SA_DISPATCH(*openpar, 2) = MakePropertyValue("Hidden", #False)
V_ARRAY_DISP(openarray) = *openpar
;'Instancie OOo : ces deux lignes sont obligatoires avec VB dans tout code !
oSM = COMate_CreateObject("com.sun.star.ServiceManager")
FILE.S= ConvertToUrl("travail.ots")
oDesk = oSM\GetObjectProperty("createInstance('com.sun.star.frame.Destop')")
; oDoc = oDesk\GetObjectProperty("loadComponentFromURL('"+file+"', '_blank', 0," + Str(openarray) + " as variant)"
oDoc = oDesk\GetObjectProperty("loadComponentFromURL('"+file+"' , '_blank', 0, " + Str(openarray) + " as variant)")
If oDoc
oDoc\Release()
EndIf
oDesk\Release()
oSM\Release()
End
Procedure MakePropertyValue(cName.s, uValue.b)
Define.COMateObject oServiceManager,oStruct
oServiceManager = COMate_CreateObject("com.sun.star.ServiceManager")
If oServiceManager
oStruct = oServiceManager\GetObjectProperty("Bridge_GetStruct('com.sun.star.beans.PropertyValue')")
oStruct\SetProperty("Name = " + cName)
oStruct\SetProperty("Value = " + Str(uValue))
ProcedureReturn oStruct
EndIf
EndProcedure
Procedure MakePropertyValue1(cName.s, uValue.s)
Define.COMateObject oServiceManager,oStruct
oServiceManager = COMate_CreateObject("com.sun.star.ServiceManager")
If oServiceManager
oStruct = oServiceManager\GetObjectProperty("Bridge_GetStruct('com.sun.star.beans.PropertyValue')")
oStruct\SetProperty("Name = " + cName)
oStruct\SetProperty(Chr(34)+"Value = " + uValue )
ProcedureReturn oStruct
EndIf
EndProcedure
Procedure.s ConvertToUrl(strFile.s)
strFile = ReplaceString(strFile, "\", "/")
strFile = ReplaceString(strFile, ":", "|")
strFile= ReplaceString(strFile, " ", "%20")
strFile = "file:///" + strfile
ProcedureReturn strFile
EndProcedure
oDoc = oDesk\GetObjectProperty("loadComponentFromURL('"+file+"' , '_blank', 0, " + Str(openarray) + " as variant)")
May someone can help me.
What error are you getting?
**EDIT : wait I see what the problem is - or at least one problem. Checking... yes it is the safe array of iDispatch objects... COMate is not set up to return such objects from the GetObjectProperty() method (this returns a COMate object which itself contains an iDispatch object!)
Thinking...
***EDIT : okay the following untested workaround allows the MakePropertyValue() function to return an iDispatch pointer directly. It works by retrieving the Bridge_GetStruct('com.sun.star.beans.PropertyValue') property object as a variant from which the iDispatch object can easily be retrieved without any hacks!
We then temporarily wrap this object within a COMate automation object so that you can set the two properties. Note that this COMate object is released so that the reference counting is kept in order. Note also that the iDisp object which we return has had it's reference count increased and so you will eventually need to destroy the safe array in order to set this right.
You will need to make similar adjustments to the MakePropertyValue1() function.
**EDIT : wait I see what the problem is - or at least one problem. Checking... yes it is the safe array of iDispatch objects... COMate is not set up to return such objects from the GetObjectProperty() method (this returns a COMate object which itself contains an iDispatch object!)
Thinking...
***EDIT : okay the following untested workaround allows the MakePropertyValue() function to return an iDispatch pointer directly. It works by retrieving the Bridge_GetStruct('com.sun.star.beans.PropertyValue') property object as a variant from which the iDispatch object can easily be retrieved without any hacks!

You will need to make similar adjustments to the MakePropertyValue1() function.
Code: Select all
Procedure MakePropertyValue(cName.s, uValue.b)
Define.COMateObject oServiceManager,oStruct
Define *ret.VARIANT, iDisp.IDISPATCH
oServiceManager = COMate_CreateObject("com.sun.star.ServiceManager")
If oServiceManager
*ret = oServiceManager\GetVariantProperty("Bridge_GetStruct('com.sun.star.beans.PropertyValue')")
If *ret
If *ret\vt <> #VT_DISPATCH
VariantChangeType_(*ret, *ret, 0, #VT_DISPATCH)
EndIf
If *ret\vt = #VT_DISPATCH
iDisp = *ret\pdispVal
oStruct = COMate_WrapCOMObject(iDisp)
If oStruct
oStruct\SetProperty("Name = " + cName)
oStruct\SetProperty("Value = " + Str(uValue))
oStruct\Release() ;Required to keep the reference count in check.
EndIf
Else
VariantClear_(*ret)
EndIf
FreeMemory(*ret) ;We do not use VariantClear_() as we do not wish to release the iDisp object which we are returning from this function.
EndIf
EndIf
ProcedureReturn iDisp
EndProcedure
I may look like a mule, but I'm not a complete ass.
This thread is LOOONG! 
Is ActiveX supported/working?
I have project that being able to use name and address cleanup libraries in would be very helpful. Unfortunately these libraries are available as ActiveX libraries.
Thanks!
/edit=never mind, web site says it does, so I'll take it for a spin and see what "develops"...

Is ActiveX supported/working?
I have project that being able to use name and address cleanup libraries in would be very helpful. Unfortunately these libraries are available as ActiveX libraries.
Thanks!
/edit=never mind, web site says it does, so I'll take it for a spin and see what "develops"...

Hi Srod,
thanks for that!
next problem directly at next line
how is this to understand?
Best
jpd
this line help the returncode is =0 and the error descripion is ok!srod wrote:Code: Select all
objInParam.COMateObject = objShare\GetObjectProperty("Methods_('EnableStatic')\inParameters\SpawnInstance_()")
thanks for that!

next problem directly at next line

how is this to understand?
Code: Select all
objInParam.Properties_.Item("IPAddress") = "192.168.110.1"
jpd
PB 5.10 Windows 7 x64 SP1
Try
Code: Select all
objInParam\SetProperty("Properties_\Item('IPAddress') = '192.168.110.1'")
I may look like a mule, but I'm not a complete ass.