PNPDevices with 'unknown' status

Started by spl, Today at 04:47:16 AM

Previous topic - Next topic

spl

While working on a script to identify, disable, enable a PC/Laptop camera, I found that Windows also contains hidden or not-used devices with a status of 'unknown'. I read one thread about these where a contributor mentioned that MS does not allow these to be displayed with a standard WMI query [which may be inaccurate but I did try w/out success]. However, there is a PS cmdlet Get-PNPDevice which can iterate them. Below I placed a working query using Get-PNPDevice into my StdOut function for use in WB. Probably useless code for anyone reading this, but would appreciate if it could be tested.
;Iterate PNPEntity Devices with unknown status
;save as ..\StdOut_PNPUnknown.wbt
;Stan Littlefield 10/16/2024
;==========================================================
Gosub udfs

args = "Get-PnpDevice | where Status -match 'unknown' | Select-Object Status, Class, FriendlyName | ConvertTo-Csv -NoTypeInformation"
cmd="Powershell"
msg='Unknown PNPEntity Devices'

BoxOpen("Running...",cmd:" ":args:@LF:"PLEASE WAIT...MAY TAKE SOME TIME")
TimeDelay(2)
vals = Get_stdout()
vals = StrReplace(vals,'"','') ;remove quotes
Message(msg,vals) ;will probably be messy so consider file out                      
;optional - create output file with links, for further scraping
;FilePut("c:\temp\UnknownPNPDevices.txt",vals)
Exit
;==========================================================
:udfs
#DefineSubroutine Get_stdout()
ObjectClrOption("useany","System")
objInfo = ObjectClrNew("System.Diagnostics.ProcessStartInfo")
Output=""
timeOut = ObjectType("I2",5000)
objInfo.FileName = cmd
objInfo.RedirectStandardError = ObjectType("BOOL",@TRUE)
objInfo.RedirectStandardOutput = ObjectType("BOOL",@TRUE)
objInfo.UseShellExecute = ObjectType("BOOL",@FALSE)
objInfo.CreateNoWindow = ObjectType("BOOL",@TRUE)
objInfo.Arguments = args
oProcess = ObjectClrNew("System.Diagnostics.Process")
oProcess.StartInfo = objInfo
BoxShut()
oProcess.Start()
oProcess.WaitForExit(timeout)
STDOUT = oProcess.StandardOutput.ReadToEnd()
STDERR = oProcess.StandardError.ReadToEnd()
Output = Output:STDOUT:@CRLF
If STDERR<>""
   Output = Output:"STDERR:":STDERR:@CRLF
Endif
oProcess = 0
objInfo = 0

Return (Output)
#EndSubroutine
Return
;==========================================================
Stan - formerly stanl [ex-Pundit]