COMate - control COM objects via automation - OBSOLETE!

Developed or developing a new product in PureBasic? Tell the world about it.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

ts-soft wrote:
Little John wrote: With all three programs, I get the error message:
Couldn't create the ActiveX control!
Any ideas?
Register a ActiveX requires Admin privilege!
Good point. The fact that the MSComCtrlTree seems to work okay for Little John would indeed suggest that this is the problem. :)

Should XP not throw up some kind of message in this situation though?
I may look like a mule, but I'm not a complete ass.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

That solved the problem, thanks Thomas! The demos are impressive. And thanks again to srod!

Is there a way to register ActiveX controls with Admin privileges permanently, so that afterwards any normal user with restricted privileges can use them, too?

Regards, Little John

//edit
I'm too slow ...
Yes, there's no problem here with the MSComCtrlTree.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Little John wrote: Is there a way to register ActiveX controls with Admin privileges permanently, so that afterwards any normal user with restricted privileges can use them, too?
Remove the unregisterfunction in the demo code :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

Thanks again! As you already might have guessed :), I really don't know much about all this COM stuff.

Regards, Little John
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

you're welcome
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

@LittleJohn, the ActiveX demos will unregister a control only if they themselves had to register it in the first place; that is a demo will not unregister the control if it was already registered before the demo started.

So run the demo once with the unregisterfunction commented out and then you can uncomment it because the demo will not attempt to unregister the control from that point on.
I may look like a mule, but I'm not a complete ass.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

I see. Thanks for the explanation!

Regards, Little John
byo
Enthusiast
Enthusiast
Posts: 635
Joined: Mon Apr 02, 2007 1:43 am
Location: Brazil

Post by byo »

Great work as usual. ;)
Proud registered Purebasic user.
Because programming should be fun.
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

jpd wrote:Hi,

I search to use the methode EnableStatic for change the IPAddress
on the NetAdapter..

using the class Win32_NetworkAdapterConfiguration

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.
any idea ?


Code: Select all

;/////////////////////////////////////////////////////////////////////////////////
;***COMate***  COM automation through iDispatch.
;*===========
;*
;*WMI demo - renew IP addresses. By SFSxOI.
;/////////////////////////////////////////////////////////////////////////////////

IncludePath "..\.."
XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"
Define.COMateObject objWMIService, objNetCard 
colNetCards.COMateEnumObject 
Define *IPAddress.VARIANT,*ConnectID.VARIANT, *varIP.VARIANT
  *sa.SafeArray
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\GetstringProperty("IPAddress")
    *IPAddress= objNetCard\GetvariantProperty("IPAddress") 
        If *IPAddress\vt <> #VT_NULL
          *sa = *IPAddress\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
            sIPAddress.s= PeekS(*varIP\bstrVal, -1, #PB_Unicode)
            If sIPAddress="192.168.65.5"
            ;objNetCard\SetProperty("EnableStatic'(192.168.66.5,255.255.255.0)'") 
            objNetCard\SetProperty("EnableStatic($0027"+"192.168.66.5,255.255.255.0"+"$0027)") 
           Debug  COMate_GetLastErrorCode() 
           Debug COMate_GetLastErrorDescription() 

          EndIf
            VariantClear_(*varIP)
            
          Next
          saFreeSafeArray(*sa)
        EndIf
        VariantClear_(*IPAddress) : FreeMemory(*IPAddress)
        
      objNetCard\Invoke("RenewDHCPLease()") 
      objNetCard\Release() 
      objNetCard = colNetCards\GetNextObject() 
    Wend 
    colNetCards\Release() 
  EndIf 
  objWMIService\Release()  
Else
  MessageRequester("COMate - WMI demo", "Couldn't create the WMI scripting object!")
EndIf 
Thanks
jpd
I had this problem and solved it by enclosing multiple parameters with a parenthesis.

Code: Select all

Series\Invoke("Add(100, 'Europe', 255)")
Rather than

Code: Select all

Series\Invoke("Add 100, 'Europe', 255")
jpd
Enthusiast
Enthusiast
Posts: 167
Joined: Fri May 21, 2004 3:31 pm

Post by jpd »

Hi Xombie,

thanks for interest on my call!

but this methode not Help, or I'm use it not in the right manner :-(

I think that the right methode is the indicated from srod.

thanks srod!


at this time I'm to busy with another project and can spend anymore time on this problem.
But if I find in the future a solution I will post this.

Thank again

jpd
PB 5.10 Windows 7 x64 SP1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Actually jpd, Xombie has a point when I look at the following :

Code: Select all

objNetCard\SetProperty("EnableStatic($0027"+"192.168.66.5,255.255.255.0"+"$0027)")
a SetProperty should have an '=' in it!!!

There is definitely something wrong here!
I may look like a mule, but I'm not a complete ass.
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

Post by X »

Any possibility of having a 64bit version?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I am told that COMate generates an ASM error on PB 64. I should have a 64-bit OS up and running by the weekend and so should be able to take a look - although I'd be tempted to await the release version of PB 4.3 before attempting to resolve any issues.
I may look like a mule, but I'm not a complete ass.
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

Post by X »

Thanks for the news :)
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

I'm not sure if there is something wrong here or not. If I have this code:

Code: Select all

XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pbi"


Procedure OS_Version()

Define.COMateObject objWMIService, Version
colOS.COMateEnumObject
strComputer.s = "." 

objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "") 
If objWMIService 
  colOS = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_OperatingSystem')")
  If colOS 
    Version = colOS\GetNextObject() 
    While Version
      
      Debug Version\GetStringProperty("OSLanguage")
            
      Version\Release() 
      Version = colOS\GetNextObject()
    Wend
    colOS\Release() 
  EndIf
  objWMIService\Release()  
EndIf

EndProcedure
The language version code is returned properly, however, the issue i'm not sure about is the use of GetStringProperty for this. Heres why; The MSDN at http://msdn.microsoft.com/en-us/library/aa394239.aspx for the Win32_OperatingSystem class says that OSLanguage is listed As:

Data type: uint32
Access type: Read-only

In this case both GetIntegerProperty AND GetStringProperty work to retrieve the unit32 property and both return the correct value.

Why are both of them working to retrieve this property value with the latest version of Comate ? Is this a bug with Comate? Should it not be one or the other but not both?

I came across this accidently during a copy and paste when changing from GetStringProperty to GetIntegerProperty for something else and left the OSLanguage in place by accident.
Post Reply