/// <summary> ///Get device Parent/// </summary> /// <param name= "Driver" ></param> /// <returns></returns> Private Static BOOLTrygetdriveridparent (stringDriver out stringResultdeviceid) {Resultdeviceid=""; Try { intCm_locate_devnode_normal =0x00000000; intCr_success =0x00000000; UInt32 Parentinst; intCurinst =0; intPlen =0; intApiresult = Win32.cm_locate_devnodea (refcurinst, driver, cm_locate_devnode_normal); if(Apiresult! =cr_success) { return false; } Apiresult= Win32.cm_get_parent ( outParentinst, (UInt32) curinst, cm_locate_devnode_normal); if(Apiresult! =cr_success) { return false; } Apiresult= Win32.cm_get_device_id_size ( outPlen, Parentinst, cm_locate_devnode_normal); if(Apiresult! =cr_success) { return false; } Char[] Ptrinstancebuf =New Char[ -]; //get Device ID string addressApiresult = win32.cm_get_device_id (Parentinst, Ptrinstancebuf, Plen,0); if(Apiresult! =cr_success) { return false; } Resultdeviceid=New string(PTRINSTANCEBUF); return true; } Catch(Exception ecexception) {Loghelper.writeerrorlog ("Get Parent"+ecexception.message, ecexception); return false; }} [DllImport ("Setupapi.dll", SetLastError =true)] Public Static extern intCm_locate_devnodea (ref intPdndevinst,stringPdeviceid,intulflags); [DllImport ("Setupapi.dll")] Public Static extern intCm_get_parent ( outUInt32 Pdndevinst, UInt32 dndevinst,intulflags); [DllImport ("Setupapi.dll", SetLastError =true)] Public Static extern intCm_get_device_id_size ( out intPullen, UInt32 Dndevinst,intFlags =0); [DllImport ("Setupapi.dll", CharSet =CharSet.Unicode)] Public Static extern intcm_get_device_id (UInt32 Dndevinst,Char[] Buffer,intBufferlen,intFlags);
Get USB device parent or descendant