0

我正在尝试编写一个脚本来检查设备当前是否处于错误级别(在设备管理器中有一个黄色的砰砰声)。我试图自动化的最终任务是安装驱动程序,检查它是否安装正确,卸载,然后再次检查以验证它是否已卸载。我已经弄清楚了大部分,但我在 WQL 查询方面遇到了问题。我可以查询是否有任何驱动程序的错误级别不是 0,并且我可以查询是否有任何驱动程序具有特定的设备 ID,但是当我尝试同时执行这两种操作时,它会失败并显示“drivertest.vbs(4,1) Microsoft VBSCript 运行时错误: type mismatch: '[string: "Select * from Win32_"]' 这是我的代码:

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
4

2 回答 2

0

试试这个。我认为你的问题是反斜杠。那些必须在 WQL 中转义。注意 中的双反斜杠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
于 2014-09-17T19:46:36.197 回答
0

我得到了它!非常感谢@Bond 的帮助!!!这是一个太多 WHERE 语句的组合,我应该使用 LIKE 而不是 =

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

现在像冠军一样工作:-)

于 2014-09-17T20:47:23.510 回答