
COMate - control COM objects via automation - OBSOLETE!
The agent is a funny beast! I think the hide does exactly that; hiding the agent without interrupting the program! The program completes as normal. There is probably a property to determine if the Agent has been hidden, but I haven't time right now to search for it!
Have a look at the disp-interfaces behind the agent with some OLE viewer.

I may look like a mule, but I'm not a complete ass.
yes, indeed. PureDispHelper is not able to pass ByRef-Values (yet).srod wrote:I am guessing, but I don't think even DispHelper would work with this code of yours?
cool, looks good!srod wrote:As you can see I have added a 'BYREF' modifier for parameters.

i'am looking forward to your next release.
Thank you & Greetings ... Kiffi
Hygge
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
I prefer solutions which do not need libraries, so COMate is perfect for me (because it can be tested on the fly even with my PureBasic-Environment on an USB stick)...
I've downloaded the OLEviewer and scrolled around - found MS Agent Control 1.5 and 2.0 and dozens of entries. It's an try and error game for me now, because there is no entry which has a name like 'AgentViewStatus'
Michael
I've downloaded the OLEviewer and scrolled around - found MS Agent Control 1.5 and 2.0 and dozens of entries. It's an try and error game for me now, because there is no entry which has a name like 'AgentViewStatus'

Michael
@SFSxOI : right, can you please try the following code. Bear in mind that I am unable to test it and so I have no idea if this will work!
It needs mk-soft's and ts-soft's "VariantHelper_Include.pb" file which I've temporarily uploaded here because there seemed to be a slight bug with SafeArrays : http://www.purecoder.net/VariantHelper_Include.pb
I honestly have no idea if the above will work; although I do have various WMI examples running fine now. I reckon that one possible reason for the above not working correctly (if that proves to be the case) would be because I am perhaps trying to force a variant into the form of a BSTR and these particular variants may not be able to be coerced in this way!
We shall see!
It needs mk-soft's and ts-soft's "VariantHelper_Include.pb" file which I've temporarily uploaded here because there seemed to be a slight bug with SafeArrays : http://www.purecoder.net/VariantHelper_Include.pb
Code: Select all
XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"
Define.COMateObject objWMIService, IPConfig
IPConfigSet.COMateEnumObject
Define *var.VARIANT, *varIP.VARIANT
*sa.SafeArray
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
IPConfigSet = objWMIService\CreateEnumeration("ExecQuery('Select IPAddress from Win32_NetworkAdapterConfiguration')")
If IPConfigSet
IPConfig = IPConfigSet\GetNextObject()
While IPConfig
If IPConfig
*var = IPConfig\GetVariantProperty("IPAddress")
If *var\vt <> #VT_NULL
*sa = *var\parray
For i = saLBound(*sa) To saUBound(*sa)
*varIP = SA_VARIANT(*sa, i)
If *varIP\vt <> #VT_BSTR
VariantChangeType_(*varIP, *varIP, 0, #VT_BSTR)
EndIf
Debug PeekS(*varIP\bstrVal, -1, #PB_Unicode)
VariantClear_(*varIP)
Next
saFreeSafeArray(*sa)
EndIf
VariantClear_(*var)
IPConfig\Release()
EndIf
IPConfig = IPConfigSet\GetNextObject()
Wend
EndIf
EndIf
We shall see!

I may look like a mule, but I'm not a complete ass.
well, yeah its not right, COMate is new to me. I'll learn over time.srod wrote:The code you just posted... well, I'm sorry, but it's nowhere near a valid translation to Purebasic with COMate!You're attempting to execute COM methods on internal COMate objects! You have also not created an enumeration of IPAddress objects etc. Someone hasn't read the COMate manual!
You need to look at the code of mine which you ran as a test, that is how we must proceed. What your test has confirmed is that we simply need to complete the code.
The 8204 was what I was after!The 1's represent null returns, presumably from adapters with no ip address. You should modify the query to filter these values out. Should be easy enough.
The 8204 tells us that one adaptor does indeed have an ip address and the enumeration has returned a safearray of variants! All we need to do is figure out how to get our hands on the array and then the variants within the array!Difficult for me because I can't run the code in order to make tests as I proceed etc; I have no network adapters yielding any results and I do not have enough experience with SafeArrays to figure out the code whilst running blind!
Still, I'll certainly have a look tomorrow.

But, your code, the 8204, i gather from your post that we are dealing with a safearray of variants?
If you look at this class in the MSDN at: http://msdn.microsoft.com/en-us/library ... S.85).aspx it shows that IPAddress is Data type: string array - but is this a safearray?
OK, starting to get the hang of a little of it now. Heres a couple of examples using the Win32_NetworkAdapterConfiguration class and the ReleaseDHCPLease and RenewDHCPLease methods with the COmate Invoke.
First the ReleaseDHCPLease method:
and now the RenewDHCPLease method.
First the ReleaseDHCPLease method:
Code: Select all
XIncludeFile "COMate.pbi"
Define.COMateObject objWMIService, objNetCard
colNetCards.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
colNetCards = objWMIService\CreateEnumeration("ExecQuery('Select IPAddress from Win32_NetworkAdapterConfiguration')")
If colNetCards
objNetCard = colNetCards\GetNextObject()
While objNetCard
objNetCard\Invoke("ReleaseDHCPLease()")
objNetCard\Release()
objNetCard = colNetCards\GetNextObject()
Wend
colNetCards\Release()
EndIf
objWMIService\Release()
EndIf
Code: Select all
XIncludeFile "COMate.pbi"
Define.COMateObject objWMIService, objNetCard
colNetCards.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
colNetCards = objWMIService\CreateEnumeration("ExecQuery('Select IPAddress from Win32_NetworkAdapterConfiguration')")
If colNetCards
objNetCard = colNetCards\GetNextObject()
While objNetCard
Debug objNetCard\Invoke("RenewDHCPLease()")
objNetCard\Release()
objNetCard = colNetCards\GetNextObject()
Wend
colNetCards\Release()
EndIf
objWMIService\Release()
EndIf
Last edited by SFSxOI on Thu Sep 04, 2008 5:27 pm, edited 1 time in total.
You mean like this?
Code: Select all
XIncludeFile "COMate.pbi"
Define.COMateObject objWMIService, objNetCard
colNetCards.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
colNetCards = objWMIService\CreateEnumeration("ExecQuery('Select IPAddress from Win32_NetworkAdapterConfiguration')")
If colNetCards
objNetCard = colNetCards\GetNextObject()
While objNetCard
Debug objNetCard\Invoke("RenewDHCPLease()")
objNetCard\Release()
objNetCard = colNetCards\GetNextObject()
Wend
colNetCards\Release()
EndIf
objWMIService\Release()
EndIf
Last edited by SFSxOI on Thu Sep 04, 2008 5:32 pm, edited 1 time in total.
Move up one line to site before the EndIf. 
Code: Select all
colNetCards\Release()

I may look like a mule, but I'm not a complete ass.
OK, got ya. thanks. corrected code in previous post.
I was looking at the help, the use of variables wasn't real clear to me.
for example, if I package the below into a procedure like this:
how do you include a passed value - nic_index.l - in the line
colAdapters = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_NetworkAdapter Where Index= ' index_nic$)")
?
I was looking at the help, the use of variables wasn't real clear to me.
for example, if I package the below into a procedure like this:
Code: Select all
XIncludeFile "COMate.pbi"
Procedure Disable_Nic(nic_index.l)
Define.COMateObject objWMIService, Adapter
colAdapters.COMateEnumObject
strComputer.s = "."
index_nic$ = Str(nic_index)
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
colAdapters = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_NetworkAdapter Where Index= ' index_nic$)")
If colAdapters
Adapter= colAdapters\GetNextObject()
While Adapter
Debug Adapter\Invoke("Disable()")
Adapter\Release()
Adapter = colAdapters\GetNextObject()
Wend
colAdapters\Release()
EndIf
objWMIService\Release()
EndIf
EndProcedure
Disable_Nic(8)
colAdapters = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_NetworkAdapter Where Index= ' index_nic$)")
?
Last edited by SFSxOI on Thu Sep 04, 2008 5:28 pm, edited 2 times in total.