Home > Software engineering >  USB device corresponding to drive, how do you know the USB mount the drive
USB device corresponding to drive, how do you know the USB mount the drive

Time:09-22

Currently using usbview example, traverse the usb device
But do not know how to drive link

Such as a USB device mounted in drive F, or he has division F, H, etc.

CodePudding user response:

Use hardware information aren't readily available, such as chip ID + vendor ID + serial number
Some of them are no serial number

CodePudding user response:

Search "devcon?"
Fyi:
 # include "stdafx. H 
"using namespace std;
Struct {
UINT type; LPCSTR a name;
} DriveTypeFlags []={//GetDriveType return code and human-readable string table
{DRIVE_UNKNOWN, "unknown"},
{DRIVE_NO_ROOT_DIR, "invalid path"},
{DRIVE_REMOVABLE, "mobile"},
{DRIVE_FIXED, "fixed"},
{DRIVE_REMOTE, "a network drive"},
{DRIVE_CDROM, "cd-rom"},
{DRIVE_RAMDISK, "random access disk"},
{0, NULL},
};
Int _tmain () {
if (! AfxWinInit (: : GetModuleHandle (NULL), NULL, : : GetCommandLine (), 0)) {
Cerr & lt; <_T (" Fatal Error: MFC initialization failed ") & lt; return -1;
}

//get logical drive string - a: \ & lt; Null> B: \ & lt; Null> C: \ & lt; Null> . Z: \ & lt; Null>
//can also use the GetLogicalDrives instead of a string in the form of a bitmap information
TCHAR buf [200].
DWORD len=GetLogicalDriveStrings (sizeof (buf)/sizeof (TCHAR), buf);

String MSG="logical drive: \ n";
For (TCHAR * s=buf; * s; S +=_tcslen (s) + 1) {
LPCTSTR sDrivePath=s;
MSG +=sDrivePath;
MSG +="";
UINT uDriveType=GetDriveType (sDrivePath);
for (int i=0; DriveTypeFlags [I]. Name; I++) {
If (uDriveType==DriveTypeFlags [I] type) {
MSG +=DriveTypeFlags [I]. Name;
break;//
}
}
MSG +='\ n';
}
cout return 0;
}

CodePudding user response:

I also used this, behind is use examples which traverse the insertion device, and then by iterating through the vpid to match the registry
But it also seems not very fleas if multiple usb plug will cause some mistakes

CodePudding user response:

Baidu search relevant keywords,

CodePudding user response:

refer to the second floor zhao4zhong1 response:
search "devcon?"
Fyi:
 # include "stdafx. H 
"using namespace std;
Struct {
UINT type; LPCSTR a name;
} DriveTypeFlags []={//GetDriveType return code and human-readable string table
{DRIVE_UNKNOWN, "unknown"},
{DRIVE_NO_ROOT_DIR, "invalid path"},
{DRIVE_REMOVABLE, "mobile"},
{DRIVE_FIXED, "fixed"},
{DRIVE_REMOTE, "a network drive"},
{DRIVE_CDROM, "cd-rom"},
{DRIVE_RAMDISK, "random access disk"},
{0, NULL},
};
Int _tmain () {
if (! AfxWinInit (: : GetModuleHandle (NULL), NULL, : : GetCommandLine (), 0)) {
Cerr & lt; <_T (" Fatal Error: MFC initialization failed ") & lt; return -1;
}

//get logical drive string - a: \ & lt; Null> B: \ & lt; Null> C: \ & lt; Null> . Z: \ & lt; Null>
//can also use the GetLogicalDrives instead of a string in the form of a bitmap information
TCHAR buf [200].
DWORD len=GetLogicalDriveStrings (sizeof (buf)/sizeof (TCHAR), buf);

String MSG="logical drive: \ n";
For (TCHAR * s=buf; * s; S +=_tcslen (s) + 1) {
LPCTSTR sDrivePath=s;
MSG +=sDrivePath;
MSG +="";
UINT uDriveType=GetDriveType (sDrivePath);
for (int i=0; DriveTypeFlags [I]. Name; I++) {
If (uDriveType==DriveTypeFlags [I] type) {
MSG +=DriveTypeFlags [I]. Name;
break;//
}
}
MSG +='\ n';
}
cout return 0;
}
traversal type,,,

CodePudding user response:

reference d2262272d reply: 3/f
, also used this, I was taken back with examples which traverse the inserted into the device, and then by iterating through the vpid to match the registry
But it also seems not very fleas if multiple usb plug will cause some error

Yes, the two devices is not GG

CodePudding user response:

refer to 6th floor Carlyle123 response:
Quote: refer to the third floor d2262272d response:

I also used this, behind is use examples which traverse the insertion device, and then by iterating through the vpid to match the registry
But it also seems not very fleas if multiple usb plug will cause some error

Yes, the two devices is not is GG

This seems to be no, what I use is full information matching such as USB \ VID_05E3 & amp; PID_0735 & amp; REV_5410
If you only use vpid that does

CodePudding user response:

refer to 7th floor d2262272d response:
Quote: refer to the sixth floor Carlyle123 response:

Quote: refer to the third floor d2262272d response:

I also used this, behind is use examples which traverse the insertion device, and then by iterating through the vpid to match the registry
But it also seems not very fleas if multiple usb plug will cause some error

Yes, the two devices is not is GG

This seems to be no, what I use is full information matching such as USB \ VID_05E3 & amp; PID_0735 & amp; REV_5410
If you only use vpid that does


Oh, can you send a example

CodePudding user response:


Oh, can you send a example

Well today to see
 
//traverse drive
Void CGetBusRelationshipHandle: : getRegistryDiskInfo ()
{
Hkeys hkeys;//define the hkeys, to close at the end of the query,
LPCTSTR path="SYSTEM \ \ CurrentControlSet \ \ Services \ \ disk \ \ Enum";
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related