0

From a command shell (cmd.exe) Win10 the following call is correct:

.\devcon.exe disable "USB\VID_0547&PID_1002&REV_0000"

But if I do the same from powershell I get the result

No matching devices found.

The same with that:

$retDevice = Get-WmiObject Win32_PNPEntity | select PnpDeviceID | where {$_.pnpdeviceid -like "USB\VID_0547&*"}
$callparam = $(" disable"  +" " + $retDevice.pnpdeviceid.ToString()) + """"
.\devcon.exe  $callparam

If I look at the string with the following all seems correct.

$callparam | Out-Default
out -> disable USB\VID_0547&PID_1002\5&22AA7556&0&2"
makurisan
  • 467
  • 3
  • 13
  • You're missing an opening `"` in the PowerShell version. Also the deviceid is different - not sure if that's expected. – G42 Jan 19 '18 at 11:55
  • The objects returned by a `Win32_PNPEntity` query provide a method [`Disable()`](https://msdn.microsoft.com/en-us/library/dn958343.aspx). Have you tried using that instead of `devcon`? – Ansgar Wiechers Jan 19 '18 at 11:59
  • What do you mean by missing an opening. Can you be more precise? The exact device instance id is not relevant. – makurisan Jan 19 '18 at 12:00
  • `out -> disable USB\VID_0547&PID_1002\5&22AA7556&0&2"` <-- there's a single `"` at the end of your output. – Ansgar Wiechers Jan 19 '18 at 12:01
  • @Ansgar: Thanks, I test it. The code above is only a starting point for more complex code in which devcon must be used. – makurisan Jan 19 '18 at 12:03
  • I think Get-WmiObject didn't have the method with the name Disable(). If you search the web, you find a cmdlet with the name Get-Device but this doesn't work on all machines out of the box. – makurisan Jan 19 '18 at 12:14
  • In case you didn't notice, there's a link to the documentation of that method in my first comment. So, regardless of how much you think `Win32_PNPEntity` objects didn't have that method: they do. – Ansgar Wiechers Jan 20 '18 at 12:42

1 Answers1

0

use start-Process instead:

Start-Process -FilePath $PathToDevcon -ArgumentList @('enable', '"USB\VID_0547&PID_1002&REV_0000"') -WindowStyle Hidden -Wait 

WindowStyle and wait are of course optionnal

miljbee
  • 300
  • 3
  • 8
  • try it with the double quotes : @("disable", '"USB\VID_0547&PID_1002&REV_0000"'), or with both strings agregated : @('disable "USB\VID_0547&PID_1002&REV_0000"'). If none works you might have a problem elsewhere. Do you need elevated rights to run devcon ? if so run powershell.exe as admin. – miljbee Jan 19 '18 at 13:01
  • 1
    Thanks, it works with this syntax: @("enable", '"USB\VID_0547&PID_1002&REV_0000"') – makurisan Jan 19 '18 at 13:10