0

I'm trying to write a script that will check if a device is currently at an error level (has a yellow bang in Device Manager). The ultimate task I'm trying to automate is installing a driver, checking if it installed correctly, uninstalling, and then checking again to verify that it uninstalled. I've got most of that figured out but I am having trouble with the WQL query. I can query if any drivers have an error level other than 0, and I can query if any drivers have a specific device ID, but when I try to do both it fails with "drivertest.vbs(4,1) Microsoft VBSCript runtime error: type mismatch: '[string: "Select * from Win32_"]' This is the code I have:

strComputer = "."
Set objWMIService = GetObject(_
    "winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_PnPEntity " _
        & "WHERE ConfigManagerErrorCode <> 0" AND "WHERE objItem.DeviceID = 'acpi\int33d6'")
For Each objItem in colItems
    Wscript.Echo "Class GUID: " & objItem.ClassGuid
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Service: " & objItem.Service
Next
  • Why is your `AND` outside of quotes? Try `"Select * from Win32_PnPEntity WHERE ConfigManagerErrorCode <> 0 AND objItem.DeviceID = 'acpi\int33d6'"` – Bond Sep 17 '14 at 18:05
  • If I have the whole thing in quotes like you suggested, I get an "unterminated string constant" if I change it to `"Select * from Win32_PnPEntity" _ "WHERE ConfigManagerErrorCode <> 0 AND objItem.DeviceID = 'acpi\int33d6'"`I get "drivertest.vbs(7,1) (null): 0x80041017 which according to the error list I found is a syntax error. The original code had the "select *..." in quotes and the "WHERE..." in quotes as well, instead of both in quotes together (if you follow me..) As you can probably tell, programming is not my forte... – Andrew Bowers Sep 17 '14 at 18:17
  • Do it the way I showed in my first comment but put everything on one line. Splitting the string among multiple lines is just going to make things more confusing for the time being. – Bond Sep 17 '14 at 18:33
  • Same error except it changes to (5,1), I'm guessing that is referring to line 5 column 1, which is the start of the `For Each objItem in collItems` line, but at least I got rid of the "unterminated string constant" error. – Andrew Bowers Sep 17 '14 at 19:31

2 Answers2

0

Try this. I think your problem is the backslash. Those must be escaped in WQL. Note the double backslash in acpi\\int33d6.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PnPEntity WHERE ConfigManagerErrorCode<>0 AND DeviceID='acpi\\int33d6'")

For Each objItem In colItems
    Wscript.Echo "Class GUID: " & objItem.ClassGuid
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Service: " & objItem.Service
Next
Bond
  • 16,071
  • 6
  • 30
  • 53
  • Still the same issue :-( Google is no help with the error code either, just that it's a syntax error. Doesn't seem to matter what I do with that line I still get the error, but it points to the `For Each` line, leads me to believe that either it's not picking up the end of the query as such, or there is an invisible character somewhere in my code that's confusing the interpreter. – Andrew Bowers Sep 17 '14 at 20:12
  • Did you copy and paste the code above? I had to make a couple other changes (you had `objItem.DeviceID` in your WQL, which wasn't right). But this code works fine for me. – Bond Sep 17 '14 at 20:22
0

I got it! Much thanks to @Bond for your help!!! It was a combination of one too many WHERE statements, and I should have been using LIKE instead of =

strComputer = "."
Set objWMIService = GetObject(_
    "winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_PnPEntity WHERE DeviceID LIKE   '%int33d6%' AND ConfigManagerErrorCode <> 0")

For Each objItem in colItems
    Wscript.Echo "Class GUID: " & objItem.ClassGuid
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Service: " & objItem.Service
Next

Works like a champ now :-)