473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.ProductName 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.Arguments.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.Arguments.Item(0)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
strResultsFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Results_" & Replace(TimeNow(Now), "-", "") & ".csv"
strNoContactFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "NoContact_" & Replace(TimeNow(Now), "-", "") & ".txt"
Set objOutputFile = objFSO.CreateTextFile(strResultsFile, True)
objOutputFile.Write "Host Name,IP Address(es),Serial Number,Model, Office Path, Install Date, Last Accessed, Product Name, Version"
Set objNoContactFile = objFSO.CreateTextFile(strNoContactFile, True)
While Not objInputFile.AtEndOfStream
strComputer = objInputFile.ReadLine
If Ping(strComputer) = True Then
On Error Resume Next
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonat e}!\\" & strComputer & "\root\cimv2")
If Err.Number = 0 Then
On Error GoTo 0

' GET THE IP ADDRESS(ES)
Set colComputerIP = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration")

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.IPAddress(intIPCount)
Else
strIPAddress = strIPAddress & ";" & IPConfig.IPAddress(intIPCount)
End If
Next
End If
Next

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

For Each objBIOS In colBIOS
strSN = objBIOS.SerialNumber
Next

' GET THE COMPUTER MODEL AND HOSTNAME
Set colComputer = objWMIService.ExecQuery _
("Select Model, Name from Win32_ComputerSystem")

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.ExecQuery("SELECT Name,Drive,InstallDate,LastAccessed,Version,and ProductName FROM CIM_DataFile WHERE (Name = 'c:\\Program Files\\Microsoft Office\\Office\\WINWORD.EXE'or Name = 'd:\\Program Files\\Microsoft Office\\Office\\WINWORD.EXE'or Name = 'c:\\Program Files\\Microsoft Office\\Office10\\WINWORD.EXE'or Name = 'd:\\Program Files\\Microsoft Office\\Office10\\WINWORD.EXE' or Name = 'c:\\Program Files\\Microsoft Office\\Office11\\WINWORD.EXE'or Name = 'd:\\Program Files\\Microsoft Office\\Office11\\WINWORD.EXE'or Name = 'c:\\Program Files\\Microsoft Office\\Office12\\WINWORD.EXE'or Name = 'd:\\Program Files\\Microsoft Office\\Office12\\WINWORD.EXE')", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
OfficeFound = False

For Each ObjItem In colItems
strVersion = objItem.Name
strInstall = objItem.InstallDate
strAccessed = objItem.LastAccessed
strSWVersion = objItem.Version
strProductName = objItem.ProductName
OfficeFound = True
Next

If (OfficeFound = True) Then

objOutputFile.Write VbCrLf & Trim(strHostname) & "," & Trim(strIPAddress) & "," & Trim(strSN) & "," & Trim(strModel) & "," & Trim(strVersion) & "," & WMIDStringToDate(strInstall) & "," & WMIDStringToDate(strAccessed) & "," & Trim(strProductName)& "," & Trim(strSWVersion)
Else
objOutputFile.Write VbCrLf & Trim(strHostname) & "," & Trim(strIPAddress) & "," & Trim(strSN) & "," & Trim(strModel)
End If
Else
Err.Clear
On Error GoTo 0
objNoContactFile.WriteLine Trim(strComputer)



End If
Else
objNoContactFile.WriteLine Trim(strComputer)
End If
Wend
objInputFile.Close
objOutputFile.Close
objNoContactFile.Close
Set objInputFile = Nothing
Set objOutputFile = Nothing
Set objNoContactFile = Nothing

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

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

Function TimeNow(dDateTime)
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 WMIDStringToDate(dtmDate)
'WScript.Echo dtm:
WMIDStringToDate = (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
Feb 24 '10 #1
0 1215

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David | last post by:
Hi, I have a MySQL database and in the front-end software I am using to Run MySQL, I have created a query on the tables which runs in the front-end, similar to the MS Access query grid. I now...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
1
by: Frank Py | last post by:
I found this great rollup query example that uses grouping and sub totals. Would it be possible to expand on this and include a group within a group and subtotal each group? For example, parent...
1
by: Gary T. | last post by:
I have a table called tbl_QuoteDetails QuoteNo Prim Key fkeyProductID foreign key Paneltype Length Price Another table called tbl_Product: ProductID Primary Key ProductName
2
by: TD | last post by:
I have this expression in the criteria section of a query: IIf(Forms!frmReports!cboProductID="<ALL PRODUCTS>",. Like "*",Forms!frmReports!cboProductID) (the syntax of the above expression may...
2
by: Judy Ward | last post by:
I can execute the following in SQL Query Analyzer: Select productID, productName from Products where productName LIKE '%Spider%' and get the results I was expecting. I must be using the wrong...
1
by: smilesinblues | last post by:
Hi, I have these 3 tables in my DB. 1. tbl.Member a. name b. email c. username(pri key) ...and other stuff 2. tbl.Product
4
by: rdraider | last post by:
Use the Northwind database Products table as an example. Purchasing dept gets a report showing when inventory items on hand qty are below the reorder level. easy enough: Select ProductID,...
12
kcdoell
by: kcdoell | last post by:
Hello: I just learned how to put crosstabs queries together but this one in particular is adding a new dimension in which I was hoping someone could give me some direction. I have the following...
2
kcdoell
by: kcdoell | last post by:
Hello: I am trying to create a union query but do not have a lot of experience. Basically I have the below tables: The Tables: Table Name = tblPrior CreditRegIDFK; Number; Foreign Key...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.