Jump to content

Recommended Posts

Posted (edited)

I can`t figure out what is wrong with this script

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

$colItems = ^ ERROR

Func _ComputerGetSoftware(ByRef $aSoftwareInfo)
Local $colItems, $objWMIService, $objItem
Dim $aSoftwareInfo[1][13], $i = 1
$objWMIService = ObjGet("winmgmts:\\" & $cI_Compname & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][13]
$aSoftwareInfo[$i][0] = $objItem.Name
$aSoftwareInfo[$i][1] = $objItem.Caption
$aSoftwareInfo[$i][2] = $objItem.Description
$aSoftwareInfo[$i][3] = $objItem.IdentifyingNumber
$aSoftwareInfo[$i][4] = $objItem.InstallDate
$aSoftwareInfo[$i][5] =  __StringToDate($objItem.InstallDate2)
$aSoftwareInfo[$i][6] = $objItem.InstallLocation
$aSoftwareInfo[$i][7] = $objItem.InstallState
$aSoftwareInfo[$i][8] = $objItem.Name
$aSoftwareInfo[$i][9] = $objItem.PackageCache
$aSoftwareInfo[$i][10] = $objItem.SKUNumber
$aSoftwareInfo[$i][11] = $objItem.Vendor
$aSoftwareInfo[$i][12] = $objItem.Version
$i += 1
Next
$aSoftwareInfo[0][0] = UBound($aSoftwareInfo) - 1
If $aSoftwareInfo[0][0] < 1 Then
SetError(1, 1, 0)
EndIf
Else
SetError(1, 2, 0)
EndIf
EndFunc

does anyone has an idea?

Edited by Jochem
Posted

You're missing stuff.

AutoIt3 Syntax Checker v1.54.8 Copyright © Tylo 2007

C:\Documents and Settings\rcmaeh01\Desktop\test.au3(4,54) : WARNING: $cI_Compname: possibly used before declaration.

$objWMIService = ObjGet("winmgmts:\\" & $cI_Compname &

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\rcmaeh01\Desktop\test.au3(5,103) : WARNING: $wbemFlagReturnImmediately: possibly used before declaration.

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", $wbemFlagReturnImmediately +

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\rcmaeh01\Desktop\test.au3(5,125) : WARNING: $wbemFlagForwardOnly: possibly used before declaration.

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\rcmaeh01\Desktop\test.au3(4,54) : ERROR: $cI_Compname: undeclared global variable.

$objWMIService = ObjGet("winmgmts:\\" & $cI_Compname &

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\rcmaeh01\Desktop\test.au3(14,62) : ERROR: __StringToDate(): undefined function.

$aSoftwareInfo[$i][5] = __StringToDate($objItem.InstallDate2)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\rcmaeh01\Desktop\test.au3 - 2 error(s), 3 warning(s)

>Exit code: 2 Time: 0.370

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11, MSEdgeRedirect
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Posted (edited)

If Not(IsDeclared("$cI_CompName")) Then
 
Global $cI_CompName = @ComputerName
EndIf
Global $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20

and this is the string to date function that i Use:

Func __StringToDate($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 ;__StringToDate Function created by SvenP Modified by JSThePatriot
Edited by Jochem
Posted

AutoIt3 Syntax Checker v1.54.8 Copyright © Tylo 2007

C:\Documents and Settings\rcmaeh01\Desktop\test.au3 - 0 error(s), 0 warning(s)

>Exit code: 0 Time: 0.251

I'm getting no errors.

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11, MSEdgeRedirect
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Posted

but for those errors I have an error handler included:

$oErrors = ObjEvent("AutoIt.Error", "Error_Handle")
 
 
Func Error_Handle()
MsgBox(0, "Debug Information", "An error has occured!" & @CRLF & @CRLF & _
"err.description is: " & @TAB & $oErrors.description & @CRLF & _
"err.windescription:" & @TAB & $oErrors.windescription & @CRLF & _
"err.number is: " & @TAB & Hex($oErrors.number, 8) & @CRLF & _
"err.lastdllerror is: " & @TAB & $oErrors.lastdllerror & @CRLF & _
"err.scriptline is: " & @TAB & $oErrors.scriptline & @CRLF & _
"err.source is: " & @TAB & $oErrors.source & @CRLF & _
"err.helpfile is: " & @TAB & $oErrors.helpfile & @CRLF & _
"err.helpcontext is: " & @TAB & $oErrors.helpcontext & @CRLF & @CRLF & @CRLF, 5)
Return SetError($oErrors.number)
EndFunc   ;==>Error_Handle

isn't this enough. Do I need another error handle

Posted

After this line :$objWMIService = ObjGet("winmgmts:\\" & $cI_Compname & "\root\CIMV2")Put an IsObj($objWMIService) check . IF WMI is damaged - it wont be an object.

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...