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-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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

 


√-1 2^3 ∑ π, and it was delicious!

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
      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
      Example:
      #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
      Version: 1.0.3
      AutoItObject_Internal.au3
      Documentation:
       

      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.
    • Nareshm
      By Nareshm
      How to repeat my script when my control class does not match ?
       
      My Script : winActivate ( " PS :: Version - 2.2.0.0  - [PS Bill]")                   ControlClick ( "PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]")                   ControlSend(" PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]", "{enter}")                   WinActive ("Verification Number Entry ::")                   ControlClick("Next >", "","[NAME:btnNext]") ;if   >>>> Control <<<<  does not match repeat my script, ;if match exit script  

      Class:    WindowsForm734a
      Instance:    15
      ClassnameNN:    WindowsForm34a15
      Name:    BillPrint
      Advanced (Class):    [NAME:BillPrint]
      ID:    7875
      Text:    
      Position:    39, 310
      Size:    1221, 306
      ControlClick Coords:    745, 20
      Style:    0x56010000
      ExStyle:    0x00000000
      Handle:    0x00000000000C0468
    • SkysLastChance
      By SkysLastChance
      I am not sure why I am getting the this error on my second pass of the code.
      1 - $oWorkbook is not an object or not a workbook object
      Any help or advice on my code appreciated. 
      #include <Excel.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") Global $vRow = 2 If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,"Untitled","A2",3) $oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92",Default,$xlWhole) $Clip = _ArrayToClip($oFind,"",0,0,"",2,2) Send("{ScrollLock Off}") $hWnd = WinWait("[CLASS:XLMAIN]") ControlSend($hWnd, "", "", ("^g")) WinWait("[CLASS:bosa_sdm_XL9]") ; Go To ControlSend($hWnd, "", "", ("^v")) ControlSend($hWnd, "", "", ("{Enter}")) ControlSend($hWnD, "", "", "{Down " & $vRow & "}") Do $oTime = _Excel_RangeRead ($oExcel2,"Untitled","B2",3) If @error Then Exit MsgBox(0, "Error", "Error" & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox(0,"Test",$oTime) IF $oTime = "7:10:00 AM" Then $oCalls1 = _Excel_RangeRead ($oExcel2,Default,"C" & $vRow,3) $oCalls2 = _Excel_RangeRead ($oExcel2,Default,"D" & $vRow,3) ControlSend($hWnd, "", "", $oCalls1) ControlSend($hWnd, "", "", ("{RIGHT}")) ControlSend($hWnd, "", "", $oCalls2) $vRow = $vRow + 1 ContinueLoop Else $vRow = $vRow + 1 EndIf Until $vRow = 4 1.xlsm
      2.xlsx
    • TrashBoat
      By TrashBoat
      Is this possible:
      Executing a function from an include, but taking the function name from a gui input and then executing that function using the include:
      #include <Something.au3> ;input reads "Tree" $functionName = GuiCtrlRead($input1) $functionName(1) And the include is gonna have
      Func Tree($x) If $x = 1 Then $this = "text" MsgBox(0,$this,"whatever") EndFunc is it possible?
    • IamKJ
      By IamKJ
      So I have a lot of different functions in the little program I'm making.  Most of them use the Do statement, such as finding images, clicking buttons, etc.
       
      The question I have is how would I be able to both
      1) Create a hotkey to pause whatever I am doing at the moment.  If I have to put something into every function in the program, I don't mind.
      2) Create a hotkey to exit whatever I am doing and stop all loops or commands and bring back the main GUI?