8 posts in this topic
following my previous question, I have moved all potentially instable object interactions into Executes. But it Looks like "="-assignments to object Attributes cannot be done with Execute, only method calls. Using an "$obj = 1" construct, it compares (Eval) instead of sets (Execute) the value.
I have tested multiple different combinations, using Execute and Assign, but it seems not to work with object Attributes. :-(
Gives following Output:
The assign Action using apply (a3) Fails, while assigning it directly, without Assign() works fine.
The execute versions compare and do not assign, in both cases. Though, the "Execute" topic in the help file says it executes, not evaluates.
I have found a similar, old thread, which explains this behavious but does not give a solution. https://www.autoitscript.com/forum/topic/110228-pass-object-property-as-a-variable/
Is there a way to assign to a com object's Attribute? Or is there anything new to this unexpected behaviour of Execute (at least compared to the help file description and Python's exec).
Any help is appreciated, and thank you for all the help so far.
I've made a library, based on AutoItObject UDF with the goal of implementing getter and setter functionality and make it possible to define new object properties in as few steps as possible.
Thank you to @trancexx for getting me on the right track, and all users in Hooking into the IDispatch interface for the code to get me going.
If I've forgotten to add credit, please let me know
#include "AutoItObject_Internal.au3" $myCar = IDispatch() $myCar.make = 'Ford' $myCar.model = 'Mustang' $myCar.year = 1969 $myCar.__defineGetter('DisplayCar', DisplayCar) Func DisplayCar($oThis) Return 'A Beautiful ' & $oThis.parent.year & ' ' & $oThis.parent.make & ' ' & $oThis.parent.model EndFunc MsgBox(0, "", $myCar.DisplayCar) More examples: https://github.com/genius257/AutoIt-projects/tree/master/AutoItObject Internal/Examples
Edit2 (19th March 2017):
First of all, sorry about the lack of updates on this project. I always start too many projects and end up ignoring old projects, if I run into problems ^^'.
So I've started moving my AutoIt scripts to GitHub. I will still post the most recent script version here.
I've coded the small script below, but it can't seem to get the instance of Windows Media player as it keeps going to @error, I've not used com objects before so any assistance would be appreciate. I already have WMP open and minimised. I retrieved "WMPlayerApp" from the AutoIT info tool, I've included a copy below.
I'm using these sources:
$oWMP = ObjGet("", "WMPlayerApp") If @error Then MsgBox(0, "Can't get WMP", "Couldn't connect to the WMP instance") Exit EndIf $wmpPlayState = $oWMP.playState MsgBox(0, "Play State", $wmpPlayState) $wmpSongName = $oWMP.currentMedia.name MsgBox(0, "Play State", $wmpSongName) I've also seen references to the below, but I want to get an existing open WMP:
ObjCreate("wmplayer.OCX") and have looked at the WMP.udf but can't see how it will do either of the functions I've coded above.
I need help, I found script to check computer model. I want use it in loop to chceck multiple pc`s (targets.txt with computer names).
But when i try use inside loop i get error: Variable must be of type "Object" and I dont know how to fix this
Local $targets = @ScriptDir& "\targets.txt" Local $log_name = "\scan.log" $msgBox = MsgBox(4, "Scan", "need tergets.txt") Example() Func Example() If $msgBox = 7 Then exit EndIf If Not FileExists($targets) Then MsgBox($MB_SYSTEMMODAL, "", "File: targets.txt - no exist !") Exit EndIf FileOpen($targets, 0) Global $arr ReDim $arr[_FileCountLines($targets)+1] For $i = 1 to _FileCountLines($targets) $line = FileReadLine($targets, $i) $arr[$i] = $line ; chceck if pc is online Local $iPing = Ping($arr[$i], 250) If $iPing Then ; ONLINE Local $strComputer = $arr[$i] $colItems = "" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _ "0x10" + "0x20") If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Vendor: " & $objItem.Vendor & @CRLF $Output = $Output & "SN: " & $objItem.IdentifyingNumber & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "UUID: " & $objItem.UUID & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystemProduct" ) Endif Else ;OFFLINE _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" OFFLINE") EndIf Next EndFunc
I have a problem here. I have a Script wich opens a Gui with an iExplore Object embedded. The GuiCreate is in an external Function an called in the main while of the script.
When the Gui closes the Gui gets destoyed. But unfortunately the iExplore Obejct still remains. You can see this by the RAM usage of the exe. After opening a Website the RAM usage stays at ~ 50 Mb RAM (depending on the website).
I want it to fall back to the normal state (around 4 MB).
You can see my attempts to delete the object properly. According to the help an embedded object should get deleted when the GUI gets deleted ...?
GUICreate("Display", 600, 360, -1, -1) Local $oIE = _IECreateEmbedded() $obj = GUICtrlCreateObj($oIE, 0, 0, 600, 360) GUICtrlSetColor(-1, 0xff0000) _IEPropertySet($oIE, "addressbar", False) _IEPropertySet($oIE, "menubar", False) _IEPropertySet($oIE, "statusbar", False) _IEPropertySet($oIE, "toolbar", False) _IEPropertySet($oIE, "resizable", False) _IENavigate($oIE, $dest&"\index.html") GUISetState(@SW_SHOW) While 1 Local $iMsg = GUIGetMsg() Local $tmsg = TrayGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE ;~ $obj = 0 ;~ _WinAPI_DeleteObject ( $obj ) ;~ _IEQuit($obj) ;~ _MemGlobalFree($obj) ;~ $oIE = 0 ;~ _WinAPI_DeleteObject ( $oIE ) ;~ _IEQuit($oIE) ;~ _MemGlobalFree($oIE) GUIDelete() Case $tmsg = $exit _exit() EndSelect WEnd
I would be very happy for your help