Query doesn't like objItem.ProductName

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MSenter
    New Member
    • Feb 2010
    • 1

    #1

    Query doesn't like objItem.ProductName

    I am trying to write a script that gives me the Version of Microsoft Office that is on all of the computers at the office (along with a few other things). I can get it to output everything except which Office it is (i.e Office 200). If I take out the objItem.Product Name part it runs fine. I put it back in and I get an "Invalid Query Error, code 80041017. What am I doing wrong? Here is the entire script. Thanks

    If WScript.Argumen ts.Count = 0 Then
    MsgBox "Please drag a text file that contains computer names onto this script file for processing."
    WScript.Quit
    End If

    strInputFile = WScript.Argumen ts.Item(0)
    Set objFSO = CreateObject("S cripting.FileSy stemObject")
    Const intForReading = 1
    Set objInputFile = objFSO.OpenText File(strInputFi le, intForReading, False)
    strResultsFile = Replace(WScript .ScriptFullName , WScript.ScriptN ame, "") & "Results_" & Replace(TimeNow (Now), "-", "") & ".csv"
    strNoContactFil e = Replace(WScript .ScriptFullName , WScript.ScriptN ame, "") & "NoContact_ " & Replace(TimeNow (Now), "-", "") & ".txt"
    Set objOutputFile = objFSO.CreateTe xtFile(strResul tsFile, True)
    objOutputFile.W rite "Host Name,IP Address(es),Ser ial Number,Model, Office Path, Install Date, Last Accessed, Product Name, Version"
    Set objNoContactFil e = objFSO.CreateTe xtFile(strNoCon tactFile, True)
    While Not objInputFile.At EndOfStream
    strComputer = objInputFile.Re adLine
    If Ping(strCompute r) = True Then
    On Error Resume Next
    Set objWMIService = GetObject("winm gmts:{impersona tionLevel=imper sonate}!\\" & strComputer & "\root\cimv 2")
    If Err.Number = 0 Then
    On Error GoTo 0

    ' GET THE IP ADDRESS(ES)
    Set colComputerIP = objWMIService.E xecQuery _
    ("Select IPAddress from Win32_NetworkAd apterConfigurat ion")

    strIPAddress = ""
    For Each IPConfig in colComputerIP
    If Not IsNull(IPConfig .IPAddress) Then
    For intIPCount = LBound(IPConfig .IPAddress) To UBound(IPConfig .IPAddress)
    If strIPAddress = "" Then
    strIPAddress = IPConfig.IPAddr ess(intIPCount)
    Else
    strIPAddress = strIPAddress & ";" & IPConfig.IPAddr ess(intIPCount)
    End If
    Next
    End If
    Next

    ' GET THE SERIAL NUMBER
    Set colBIOS = objWMIService.E xecQuery _
    ("Select SerialNumber from Win32_BIOS")

    For Each objBIOS In colBIOS
    strSN = objBIOS.SerialN umber
    Next

    ' GET THE COMPUTER MODEL AND HOSTNAME
    Set colComputer = objWMIService.E xecQuery _
    ("Select Model, Name from Win32_ComputerS ystem")

    For Each objComp In colComputer
    strModel = objComp.Model
    strHostname = objComp.Name
    Next

    ' GET THE OFFICE VERSION, INSTALL DATE, AND LAST ACCESSED DATE
    Set colItems = objWMIService.E xecQuery("SELEC T Name,Drive,Inst allDate,LastAcc essed,Version,a nd ProductName FROM CIM_DataFile WHERE (Name = 'c:\\Program Files\\Microsof t Office\\Office\ \WINWORD.EXE'or Name = 'd:\\Program Files\\Microsof t Office\\Office\ \WINWORD.EXE'or Name = 'c:\\Program Files\\Microsof t Office\\Office1 0\\WINWORD.EXE' or Name = 'd:\\Program Files\\Microsof t Office\\Office1 0\\WINWORD.EXE' or Name = 'c:\\Program Files\\Microsof t Office\\Office1 1\\WINWORD.EXE' or Name = 'd:\\Program Files\\Microsof t Office\\Office1 1\\WINWORD.EXE' or Name = 'c:\\Program Files\\Microsof t Office\\Office1 2\\WINWORD.EXE' or Name = 'd:\\Program Files\\Microsof t Office\\Office1 2\\WINWORD.EXE' )", "WQL", wbemFlagReturnI mmediately + wbemFlagForward Only)
    OfficeFound = False

    For Each ObjItem In colItems
    strVersion = objItem.Name
    strInstall = objItem.Install Date
    strAccessed = objItem.LastAcc essed
    strSWVersion = objItem.Version
    strProductName = objItem.Product Name
    OfficeFound = True
    Next

    If (OfficeFound = True) Then

    objOutputFile.W rite VbCrLf & Trim(strHostnam e) & "," & Trim(strIPAddre ss) & "," & Trim(strSN) & "," & Trim(strModel) & "," & Trim(strVersion ) & "," & WMIDStringToDat e(strInstall) & "," & WMIDStringToDat e(strAccessed) & "," & Trim(strProduct Name)& "," & Trim(strSWVersi on)
    Else
    objOutputFile.W rite VbCrLf & Trim(strHostnam e) & "," & Trim(strIPAddre ss) & "," & Trim(strSN) & "," & Trim(strModel)
    End If
    Else
    Err.Clear
    On Error GoTo 0
    objNoContactFil e.WriteLine Trim(strCompute r)



    End If
    Else
    objNoContactFil e.WriteLine Trim(strCompute r)
    End If
    Wend
    objInputFile.Cl ose
    objOutputFile.C lose
    objNoContactFil e.Close
    Set objInputFile = Nothing
    Set objOutputFile = Nothing
    Set objNoContactFil e = Nothing

    MsgBox "Finished processing the input file." & VbCrLf & "Results are in: " & strResultsFile & VbCrLf & "PCs not found: " & strNoContactFil e

    Function Ping(strCompute r)
    Dim objShell, boolCode
    Set objShell = CreateObject("W Script.Shell")
    boolCode = objShell.Run("P ing -n 1 -w 300 " & strComputer, 0, True)
    If boolCode = 0 Then
    Ping = True
    Else
    Ping = False
    End If
    End Function

    Function TimeNow(dDateTi me)
    TimeNow = Year(Now) & "-" &_
    Right("00" & Month(Now), 2) & "-" &_
    Right("00" & Day(Now), 2) & "-" &_
    Right("00" & Hour(Now), 2) & "-" &_
    Right("00" & Minute(Now), 2) & "-" &_
    Right("00" & Second(Now), 2)
    End Function

    Function WMIDStringToDat e(dtmDate)
    'WScript.Echo dtm:
    WMIDStringToDat e = (Mid(dtmDate, 5, 2) & "/" & _
    Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
    & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
    End Function
Working...