I'm looking here to get the PID and VID for a plugged in USB drive:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR\Enum
Problem is that when there is more than one drive plugged in I need to know what the driver letter is for each case because I look for a file on a specific USB drive that is encrypted with the PID and VID.
For example, in the picture below, what is the driver letter for 0 and 1 (VID_0930 and VID_0951)
I want to loop through all these plugged in drives and check if the file exists on the drive, if so, get the PID and VID of that drive.
string zeros = "";
drives = DriveInfo.GetDrives();
for (int i = 0; i < drives.Length; i++)
{
driveInfo = drives[i];
//MessageBox.Show(driveInfo.ToString());
//&& driveInfo.DriveType == DriveType.Removable
//&& driveInfo.DriveType != DriveType.Unknown
//if (driveInfo.IsReady)
// {
// MessageBox.Show(driveInfo.ToString());
dl = driveInfo.ToString();
// MessageBox.Show(dl + "TechKey.txt");
if (File.Exists(dl + "TechKey.txt"))
{
techkey = dl + "TechKey.txt";
// here I need to code for if more than one drive is plugged in.
RegValue = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR\Enum", "0",
0).ToString();
string[] rv = RegValue.Split("\\".ToCharArray());
//rv[1] holds our Vid&Pid, lets go get it.
//Lets split the string of Vid and Pid from & inbetween
string[] rv2 = rv[1].Split("&".ToCharArray());
//Now Vid and Pid are in an array alone. Lets get their Numbers!
//First Vid
Match Vid = Regex.Match(rv2[0], @"(?<=VID_)\w*");
//Now Pid
Match Pid = Regex.Match(rv2[1], @"(?<=PID_)\w*");
// Store the serial number only (excluding VID and PID)
string RealSerial = rv[2];
//Assign Original Serial
OriginalSerial = RealSerial;
//trim left characters off the serial > 16
if (RealSerial.Length == 16)
{
TechEnd = RealSerial;
}
if (RealSerial.Length > 16)
{
TechEnd = RealSerial.Substring(RealSerial.Length - 16);
//mystring.Substring(mystring.Length - 4);
}
if (RealSerial.Length < 16)
{
for (i = 0; i < (16-RealSerial.Length);i++)
{
zeros = zeros + "0";
}
TechEnd = zeros + RealSerial;
//mystring.Substring(mystring.Length - 4);
}
//MessageBox.Show(RealSerial + "L: " + RealSerial.Length);
//MessageBox.Show("Tech End" + TechEnd);
CompleteSerial = Vid.ToString() + Pid.ToString() + TechEnd;
//MessageBox.Show(CompleteSerial.ToString() + "is your complete serial for the key inside");
}