harvester2001

Variable must be of type "Object" inside loop

4 posts in this topic

Hi

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 :(

Plz help

 

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[1000]
   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

 

 

Share this post


Link to post
Share on other sites



Can you please post the error message from the SciTE output pane?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-02-03 - Version 1.4.7.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-03 - Version 1.2.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@harvester2001 the error is telling you that one of the objects does not exist. You have IsObj statement for your query, but not for the connection to WMI. Try something like this to catch the error (you'll have to massage it a little for your needs):

#include <File.au3>
#include <MsgBoxConstants.au3>

Local $oWMI, $oItems
Local $aTargets = FileReadToArray(@DesktopDir & "\PCs.txt")
    If IsArray($aTargets) Then
        For $sPC In $aTargets
            If Ping($sPC, 250) Then
                $oWMI = ObjGet("winmgmts:\\" & $sPC & "\root\CIMV2")
                    If IsObj($oWMI) Then
                        $oItems = $oWMI.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", "0x10" + "0x20")
                            If IsObj($oItems) Then
                                For $sOS In $oItems
                                    ConsoleWrite("Vendor: " & $sOS.Vendor & @CRLF & _
                                                 "SN: " & $sOS.IdentifyingNumber & @CRLF & _
                                                 "Name: " & $sOS.Name & @CRLF & _
                                                 "UUID: " & $sOS.UUID & @CRLF)
                                Next
                            Else
                                Msgbox($MB_OK,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystemProduct" )
                            Endif
                    Else
                        MsgBox($MB_OK, "WMI Output", "Could not connect to WMI on " & $sPC)
                    EndIf
            Else
                ;OFFLINE
                _FileWriteLog(@ScriptDir & "\Mylog.log", $sPC & " OFFLINE")
            EndIf
        Next
    EndIf

 


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

@JLogan3o13 thank you so much :) Now I know how to fix this :)

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • kevin42036
      By kevin42036
      Hi All,

      I am new to AutoIt and programming in general so any help would be greatly appreciated! 

      I am trying to create a script mainly using MouseClick and WinWait in order to automate some web processes. However, due to the lag time of the web pages and fields, sometimes my script does not run properly and I need to rerun it. I am trying to create a script that will check to see if the final line of the script was properly executed and if not, rerun the program and increase a count. Ultimately I would like some sort of report that tells me how many times it took to run to completion and total time. 

      Does anyone have any suggestions as to which functions I can use to accomplish this? I am also open to any suggestions on a better process to ensure that my program runs to completion.

      Thanks in advance!

      Kevin
    • SkysLastChance
      By SkysLastChance
      I know this code is not pretty by any means, but it will not loop. I have used this loop several diffrend times. 
      When I take out the this if statment it loops forever so I am guessing ti has to do with this.
      Any ideas on cleaning up code is appreciated too.
      If $r > $sBox Then Exit Endif #include <Excel.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> $sBox = InputBox ("Vital Site", "How Many Times") Excel () Logon () Sleep (2000) Auto () Func FormatDate($DATE) $SPLIT = StringSplit($DATE," ") $MM = StringMid($SPLIT[1],5,2) $YYYY = StringLeft($SPLIT[1],4) $DD = StringMid($SPLIT[1],7,2) Return $MM & "/" & $DD & "/" & $YYYY EndFunc Func Terminate() Exit EndFunc HotKeySet(("{ESC}"),"Terminate") Func Excel () While ProcessExists("EXCEL.EXE") $ms = MsgBox(5,"","Process error. You have an Excel sheet open. You must close it in order to let this program work. Please close it now.") If $ms=2 Then Exit Sleep(250) WEnd Global $sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsx)") If FileExists($sExcelFile) Then Global $oExcel = _Excel_Open () $oExcel = _Excel_BookOpen($oExcel,$sExcelFile) ;this will open the chosen xls file. Else $oExcel = _Excel_Open() $oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist. EndIf EndFunc Func Logon () $portal = ShellExecute ("C:\Program Files (x86)\MEDITECH\SSDWEB.Universe\SSDWEB.LIVEF.Ring\Client.mtad") ;MediTech WinWaitActive ("[CLASS:MagicFS]", "", "MagicFS Dispaly5") Sleep (300) ControlSend("[CLASS:MagicFS]", "", "", ("{F12}")) Sleep (700) ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}")) Sleep (700) ControlSend("[CLASS:MagicFS]", "", "", ("{DOWN}")) Sleep (700) ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}")) Sleep (700) ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}")) Sleep (700) ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}")) EndFunc WinWaitActive ("[CLASS:MagicFS]", "", "MagicFS Dispaly6") Func Auto () $r = 1 Local $aArray = _Excel_RangeRead($oExcel, Default, Default,1) For $i = 1 To UBound($aArray) - 1 ;$i =0 Start from row A $sR0 = $aArray[$i][0] ;status $sR1 = $aArray[$i][1] ;first name $sR2 = $aArray[$i][2] ;Last name $sR3 = $aArray[$i][3] ;Last 4 SSN $sR4 = $aArray[$i][4] ;DOB $sR5 = $aArray[$i][5] ;Email Address $sR6 = $aArray[$i][6] ;Mailling Address $sR7 = $aArray[$i][7] ;City $sR8 = $aArray[$i][8] ;state $sR9 = $aArray[$i][9] ;Zip Code $sR10 = $aArray[$i][10] ;Gender $sR11 = $aArray[$i][11] ;Phone ControlSend("[CLASS:MagicFS]", "", "", ("{F8}")) Sleep (500) ControlSend("[CLASS:MagicFS]", "", "", ("{F8}")) Sleep (500) ControlSend("[CLASS:MagicFS]", "", "", ("N")) ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}")) Sleep (3000) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR1 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR2 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR6& @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR7 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR8 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR9 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR11& @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR5 & @CR) ;Email7 Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR5 & @CR) ;Email Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", (FormatDate($sR4) & @CR)) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR10 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR3 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("{F8}")) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("P")) Sleep (200) $sBox = MsgBox($MB_OK & $MB_TOPMOST,"Patient Portal","After you have entered the patient push OK") Sleep (300) ControlSend("[CLASS:MagicFS]", "", "", ("{F8 3}")) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("{ESC}")) Sleep (200) ControlSend("[CLASS:MagicFS Modal(3)]", "", "", ("{ENTER}")) $r = $r + 1 If $r > $sBox Then Exit Endif Next EndFunc
    • rcmaehl
      By rcmaehl
      Alright, currently I'm trying to merge two loops:
       
      Local $aArray[99][13] For $iLoop = 1 to 100 $aArray[$iLoop - 1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop) If @error <> 0 Then ReDim $aArray[$iLoop - 1][13] ExitLoop EndIf Next For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 1 to 12 $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop Next Next  
      into one. Here's what I have so far:
       
      Local $aArray[99][13] For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 0 to 12 ConsoleWrite("Loop1 = " & $iLoop1 & ", Loop2 = " & $iLoop2 & @CRLF) If $iLoop2 = 0 Then $aArray[$iLoop1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop1 + 1) If @error <> 0 Then ReDim $aArray[$iLoop1 + 1][13] ExitLoop EndIf Else $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop EndIf Next Next And it keeps error-ing out trying to exceed the dimension range of the array. Does the Loop not recheck the size of the array after the original check or am I doing something else wrong.
       
      Thanks.
    • 31290
      By 31290
      Hi guys, 
      Hope you are fine today
      I'm trying to restart a function by calling it back in the script:
      Here's my code so far:
      Func f_VPN() $iInputBox = InputBox("Password", "Please Enter the User's password.") If @Error = 1 Then GUICtrlSetState($fVPN, $GUI_UNCHECKED) Else ShellExecute("C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe") $hVPN = WinWait("Cisco AnyConnect Secure Mobility Client", "Ready to connect") ControlClick($hVPN, "", "Button1") $hVPN1 = WinWait("Cisco AnyConnect | SEE VPN", "Cancel") ControlSetText($hVPN1, "", "Edit2", @Username) Sleep(250) ControlSetText($hVPN1, "", "Edit3", $iInputBox) Sleep(250) ControlClick($hVPN1, "", "Button1") Sleep(5000) If ControlGetText("Cisco AnyConnect Secure Mobility Client", "", "Static2") = "Login Failed" Then ControlClick("Cisco AnyConnect Secure Mobility Client", "", "Button4") WinClose($hVPN) f_VPN() Else ShellExecute("C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe") If ControlGetText("Cisco AnyConnect Secure Mobility Client", "", "Static2") = "Connected To SEE VPN." Then ControlClick("Cisco AnyConnect Secure Mobility Client", "", "Button1") Sleep(1000) WinClose("Cisco AnyConnect Secure Mobility Client", "") ProcessClose("vpnui.exe") ; ProcessClose("explorer.exe") <<< TO UNCOMMENT IniWrite($oIniFile, "LaptopChkBox", "VPN", "1") EndIf EndIf EndFunc I'd like to the function to be restarted in the case the password provided is not correct. 
      I've googled many things but nothing very relevant.
      Any ideas over here?
      Thanks
      -31290
       
    • genius257
      By genius257
      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
      Things to be added
      Garbage collection Method support Support for more/all AutoIt variable-types Accessors Inheritance equivalent of @error and @extended Example:
      #include <AutoItObject_Internal.au3> $oIDispatch = IDispatch() $__getter = DllCallbackRegister(CustomGetter, "long", "IDispatch;IDispatch") $__setter = DllCallbackRegister(CustomSetter, "long", "IDispatch;IDispatch") $oIDispatch.__defineGetter("a", $__getter) $oIDispatch.__defineSetter("a", $__setter) $oIDispatch.a = "start" MsgBox(0, "", $oIDispatch.a) $oIDispatch.a = "end" MsgBox(0, "", $oIDispatch.a) $oIDispatch.b = 3.14 $oIDispatch.b += $oIDispatch.b MsgBox(0, "", $oIDispatch.b) $oIDispatch.__defineMethod("c", FuncName(MsgBox)) $oIDispatch.c(0, "title", "text") Func CustomGetter($oIDispatch, $oIDispatch2);(return.value, this.value) $oIDispatch.a = "_" & $oIDispatch2.a & "_" EndFunc Func CustomSetter($oIDispatch, $oIDispatch2);(this.value, caller.value) $oIDispatch.a &= $oIDispatch2.a EndFunc  
      0.1.1
      AutoItObject_Internal.au3
      0.1.2
      AutoItObject_Internal.au3