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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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

    • genius257
      AutoItObject Pure AutoIt
      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 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) 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  
       
      AutoItObject_Internal.au3
    • harvester2001
      Refresh array after one loop
      By harvester2001
      Hi
      I need some help.
      I try ping computers from targets.txt (I have computer name in lines) if they ping I want do something and after that remove pc name from targets.txt. It`s working but problem is when I put this inside loop, because I need run script until all computers will not be removed from the list (targets.txt). I don`t know how to "refresh" array
      Please help
      #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Local $PC_list = "\targets.txt" Local $bTargets = FileReadToArray(@ScriptDir& $PC_list) Do _check_ping() ;count_lines Local $file_count_lines = _FileCountLines(@ScriptDir& $PC_list) $i = $file_count_lines ConsoleWrite("na liście "&$i & @CRLF) Until $i = 0 ; IF &i = 0 then show MsgBox MsgBox(1, "xXx", "Finish") ;PING Func _check_ping() For $sPC In $bTargets $var = Ping($sPC, 250) If $var Then ConsoleWrite($sPC &"online"& @CRLF) ;Do something ;Delete $sPC from targets.txt Local $_Array _FileReadToArray ( @ScriptDir& "\targets.txt", $_Array ) $_Array = _DeleteArrayElementWithStringInstr ( $_Array, $sPC ) _FileWriteFromArray ( @ScriptDir& "\targets.txt", $_Array, 1 ) Sleep(200) Else ConsoleWrite($sPC &"offline"& @CRLF) EndIf Next EndFunc ;DELETE LINE FROM TXT Func _DeleteArrayElementWithStringInstr ( $_Array, $_String ) Local $_Item For $_Element In $_Array If StringInStr ( $_Element, $_String ) <> 0 Then _ArrayDelete ( $_Array, $_Item ) Else $_Item+=1 EndIf Next Return ( $_Array ) EndFunc ;==> _DeleteArrayElementWithStringInstr ( )  
    • mond1106
      help loop parameter
      By mond1106
      how do I break the loop if my program is stuck in it without exiting the whole program?
       
      i just want it to start from the beginning of the code here is my program
       
      While 1
      $picture = "target.png"
      $result = _ImageSearch($picture,1,$x1,$y1,0,0)
      If $result = 1 Then
         Send("{4}")
         MouseClick("left",$x1,$y1,1,1)
         Sleep(2000)

         Do
         $picture2 = "status.png"
         $result2 = _ImageSearch($picture2,1,$x1,$y1,0,0)
         
         Send("{2}")
         Send("{1}")
      Until $result2 = 1
       
       
      as you see if my program doesnt detect  or see picture2 then the loop wont stop.
       

       
    • ssah8
      Display loop count
      By ssah8
      So im creating a bot that logs in on a website. The website got a dropdown menu, and I have to choose the right one to login (Student)
      #include <IE.au3>
      #inculude <Inet.au3>
      $oIE = _IECreate("https://sms14.schoolsoft.se/engelska/jsp/Login.jsp?eventMessage=ERR_Not_Logged_In")
      $Name = _IEGetObjByName($oIE, "ssusername")
      $Pass = _IEGetObjByName($oIE, "sspassword")
      $dropdown = _IEGetObjByName($oIE, "usertype")
      _IEPropertySet($Name, 'innerText', 'censored')
      _IEPropertySet($Pass, 'innerText', 'censored')
      _IEPropertySet($dropdown, 'innerText', 'Student') <------ How do I make the dropdown list select "Student"?
       
      Website: https://sms14.schoolsoft.se/engelska/jsp/Login.jsp?eventMessage=ERR_Not_Logged_In
    • RyukShini
      Array variable has incorrect number of subscripts
      By RyukShini
      Local $okay _FileReadToArray("Okay.txt", $okay) ; read the list of names to array For $i = 1 To UBound($okay) - 1 $Read = $okay[$i] If I run this and it goes to the end of Okay.txt it returns an error.
      "Array variable has incorrect number of subscripts or subscript dimension range exceeded.:"
      so can I either exitloop if its run through the file or add some error checking that exitloop if array = empty?
      Thanks in advance.