Jump to content

Recommended Posts

Posted

I have a script I put together with help from posts on here and Scriptomatic for AutoIT. What it does is check (Model) to see if a computer is a desktop or laptop and run functions I made to configure the new image for the computer.

When I run it on a desktop it works just fine, when I run it on a laptop it repeats 6 times. There is an extra step with the laptops, it only needs to run if there is a Dell WiFi card installed (Broadcom). This is the only difference between the scripts so I think the problem has to be here. I've tried changing the $objItem to other fields and verified that only one adapter fits my StringInStr field.

Any help would be greatly appreciated

Adapter function

func _AdapterTest()
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output=""
$Output &= "Computer: " & $strComputer  & @CRLF
$Output &= "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
   For $objItem In $colItems
      $Output &= "Manufacturer: " & $objItem.Manufacturer & @CRLF
      If StringInStr($Output, "Broadcom") Then
    _Laptop()

EndIf
Next
Endif
EndFunc
Func WMIDateStringToDate($dtmDate)
Return (StringMid($dtmDate, 5, 2) & "/" & _
StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
& " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

Main

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output=""
$Output &= "Computer: " & $strComputer  & @CRLF
$Output &= "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
   For $objItem In $colItems
      $Output &= "Model: " & $objItem.Model & @CRLF
   If StringInStr($Output, "OptiPlex 7") Then
  _Desktop()
EndIf
    
If StringInStr($Output, "Latitude") Then
     _AdapterTest()
 

    EndIf
Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystem" )
Endif
Posted (edited)

I'm wondering that since you're appending to $Output in every iteration of your "For $objItem In $colItems" Loop, once "Broadcom" gets into $Output once it will always be there...causing "If StringInStr($Output, "Broadcom") Then" to call _Laptop() every time once it's been found once.

Hope that makes sense?

Edited by MrMitchell
Posted

Thank you!! I changed it to "If StringInStr($objItem.Manufacturer, "Broadcom") Then" and it only runs once.

I mistakenly thought that the line

$Output &= "Manufacturer: " & $objItem.Manufacturer & @CRLF
was only looking at that $objItem but instead it was only reporting that one. I needed to have it look only at the right objItem.

Thank you again!!

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
×
×
  • Create New...