gelonida
asked on
get GUID for a device for which I know BUS / VID / and PID
Hi,
I'd like to know whether it is possible to directly find a device's GUID
if I know the BUS / VID and PID (or BUS VEN / DEV) of it
The only option that I have so far is to retrieve all devices withWMI (in my case only usb network devices), get their PNPDeviceID and parse for it.
Is there anything faster? WMI is rather slow and my code doesn't really seem elegant.
Are there options using directly the win32 module?
My current code works for python2 and python3, but as mentioned above.
I manually search through all network devices and parse the PNPDeviceID
my code:
I'd like to know whether it is possible to directly find a device's GUID
if I know the BUS / VID and PID (or BUS VEN / DEV) of it
The only option that I have so far is to retrieve all devices withWMI (in my case only usb network devices), get their PNPDeviceID and parse for it.
Is there anything faster? WMI is rather slow and my code doesn't really seem elegant.
Are there options using directly the win32 module?
My current code works for python2 and python3, but as mentioned above.
I manually search through all network devices and parse the PNPDeviceID
my code:
import wmi
c = wmi.WMI()
def find_by(bus, vid, pid):
nw_adapters = (
c.Win32_NetworkAdapter(AdapterTypeId=0)
+ c.Win32_NetworkAdapter(AdapterTypeId=9)
)
pnp_string_start = r"%s\VID_%s&PID_%s" % (bus, vid, pid)
for device in nw_adapters:
if device.PNPDeviceID.startswith(pnp_string_start):
return device
return None
def get_guid(bus, vid, pid):
device = find_by(bus, vid, pid)
return None if device is None else device.GUID
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK I see.
I must have mixed up the licensing with another tool.
What I'm confused about now is:
https://docs.microsoft.com /en-us/win dows-hardw are/driver s/devtest/ devcon seems to state, that the way to download is:
Download Windows Driver Kit (WDK) 8 and Windows Driver Kit (WDK) 8.1
Will try it out and keep you updated
I must have mixed up the licensing with another tool.
What I'm confused about now is:
https://docs.microsoft.com
Download Windows Driver Kit (WDK) 8 and Windows Driver Kit (WDK) 8.1
Will try it out and keep you updated
ASKER
Hi McKnife. Thanks a lot.
Already installing the SDK (without visual studio).
and it finished now.
file can be found after installation on
Thanks for your help. Will play with devcon
I'll leave this question still open a little longer.
Perhaps there is (though I'm afraid there's not) a win32 / ctypes / cffi solution, that's a little faster than WMI and that doesn't require subprocess calls
Already installing the SDK (without visual studio).
and it finished now.
file can be found after installation on
C:\Program Files (x86)\Windows Kits\10\Tools\x64\devcon.exe # for the 64 bit version
andC:\Program Files (x86)\Windows Kits\10\Tools\x86\devcon.exe # for the 32 bit version
Thanks for your help. Will play with devcon
I'll leave this question still open a little longer.
Perhaps there is (though I'm afraid there's not) a win32 / ctypes / cffi solution, that's a little faster than WMI and that doesn't require subprocess calls
ASKER
OK with
list of classes at docs.microsoft.com
But now back to my question: how to display now the GUID of the device?
devcon findall *
devcon listclass net
I get a list of all PNP ids and can search.list of classes at docs.microsoft.com
But now back to my question: how to display now the GUID of the device?
Good question. So far, I see only ways to retrieve the hardware ID, but not device ID, sorry.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have no other idea, sorry.
ASKER
Thanks a lot for your help. learned about devcon. Might come in handy another time.
Will continue with slow WMI solution.
Will continue with slow WMI solution.
ASKER
devcon is faster but can't return a GUID (at least I didn't find out how)
ASKER
thanks
ASKER
Will try this and see whether there is some big performance improvement.
However for many projects this could only be a fallback (falling back to WMI in case devcon cannot be found)
At the moment I create depending on the project:
either source code published on
- pypi
- github
and one only has to type
Open in new window
or I create one file with py2exe / pyinstaller
and extracting it and running the .exe is enough.
Not sure about whether / how devcon can be distributed (autoinstalled for such cases)
Might open a legal can of worms.