0

I am quite new to programming and have written a simple piece of code to check for the presence of a specific name within the windows device manager.

I am using the following library https://pypi.org/project/infi.devicemanager/

my function:

def searchdongle():
    found = 0
    devicesname = ""
    dm = DeviceManager()
    dm.root.rescan()
    devices = dm.all_devices
    for device in devices:
        #print(device)
        devicesname  = device
        print(devicesname)
        #if devicesname == "<Gaurdant Code>":
        if "Gaurdant" in devicesname and "Code" in devicesname:
           found = 1 
           print("Found it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
                
    return found 

But I cannot detect the name at all. I believe this is because Device is of type "Device" and not a string??? how would I cast this to a string to test??? I did try using the python IN operator but got the error TypeError: argument of type 'Device' is not iterable

testing both print statements yields the correct results:

resulted output

Any help appreciated thanks

Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60
Marlon
  • 1
  • In your `for loop` try `print(dir(device))`. I suspect that the device object will have `description` and `friendly_name` methods you can quiz. – Rolf of Saxony Jul 13 '22 at 08:02
  • yes, it is there 'class_guid', 'description', 'devnode_status', 'friendly_name', 'get_available_property_ids', 'hardware_ids', 'has_property', 'instance_id', 'is_hidden', 'is_iscsi_device', 'is_real_device', 'is_root', 'location', 'location_paths', 'parent', 'psuedo_device_object', 'rescan', 'ui_number'] – Marlon Jul 13 '22 at 08:40
  • though not sure how to implement 'friendly_name', in my code – Marlon Jul 13 '22 at 08:46
  • try `print(device.friendly_device)` and `print(device.description)`, whichever one fits your purpose you can then test against that i.e. `if 'Gaurdant' in device.description:` – Rolf of Saxony Jul 13 '22 at 15:15
  • Thank you, device.description was the only list that worked in the end, so all working now, again thanks for you input on the matter, much appreciated – Marlon Jul 13 '22 at 16:39
  • No problem. To clear up the question, if you post your solution as an answer yourself, you will be able to `Accept` it in a day or two. That will help others with a similar issue, find a solution in the future. – Rolf of Saxony Jul 14 '22 at 07:23

0 Answers0