Question Locked

Help with WMI Query Error 80041017

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hello All,

I am trying to execute an HTA on a WinXP box that will just show the printer information of printers on the Win2K print server, however it won't take anything as a WHERE or LIKE clause:

Set colPrinters = objWMIService.ExecQuery _
("SELECT * FROM Win32_Printer WHERE Name LIKE '\\SERVER\%'")
For Each objPrinter in colPrinters

I've tried using no ', changing LIKE to WHERE, even using a specific printer name and i keep getting this error 80041017 on the "For Each objPrinter in colPrinters" line.

Anyone have any idea why this may be happening?
Any help is appreciated.

Here is the entire .hta:

8 replies

by adam.chiarotto

not really what i am looking for.
I just need an explanation of why the WHERE clause in my WMI query refuses to work.
but thanks anyways.

by Former member

Multi posts, Internet slow down i think..

by adam.chiarotto

I ended up just forgetting about getting the WHERE clause to work and used an InStr with an IF statement to make sure i only got the printers on the print server, not locally attached.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("SELECT * FROM Win32_Printer")
For Each objPrinter in colPrinters
IF InStr(objPrinter.Name,"TERVER") THEN
Set objRow = objTableBody.InsertRow()
Set objCell = objRow.InsertCell()
objCell.InnerText = objPrinter.Name
Set objCell = objRow.InsertCell()
objCell.InnerText = objPrinter.Location
Set objCell = objRow.InsertCell()
Select Case objPrinter.PrinterStatus
Case 1
strPrinterStatus = "Other"
Case 2
strPrinterStatus = "Unknown"
Case 3
strPrinterStatus = "Idle"
Case 4
strPrinterStatus = "Printing"
Case 5
strPrinterStatus = "Warming up"
Case 6
strPrinterStatus = "Stopped Printing"
Case 7
strPrinterStatus = "Offline"
End Select
objCell.InnerText = strPrinterStatus
END IF
Next

This discussion is closed to new replies.