This function takes a drive letter (either: X, X: or X:\) and if this drive is connected to an external
usb hub the hub's "USB Port Name old" is returned. By comparing this value for two calls (with two
drive letters) you can determine if they are on the same hub or not...
You need the command line utility "ListUsbDrives" from http://www.uwe-sieber.de/usbdlm.html#download
and edit the path to it in the function to get it working...
Code: Select all
// Get the "USB Port Name old" value from a log file created
// by ListUsbDrives (http://www.uwe-sieber.de/usbdlm.html#download)
// The function returns an empty string if the drive isn't connected to a hub
function GetUSBHub($drive, $logFile="") {
// You need to adapt the path for $listUsbDrives for your system!
if (!$logFile || exists($logFile) != 1) {
$listUsbDrives = "D:\Users\Highend\Tools\USBDLM_x64\@ListUsbDrives\ListUsbDrives_x86.exe";
$logFileContent = runret("$listUsbDrives", "%windir%"); }
// $logFile given, it is a real file
elseif (exists($logFile) == 1) { $logFileContent = readfile($logFile); }
// Be a bit more tolerate on $drive definition
$drive = replace($drive, "\");
if !(regexmatches($drive, ":")) { $drive = $drive . ":"; }
// Get drive's serial number
$srcSerial = regexmatches(runret("cmd /c vol $drive", "%windir%"), "[a-f0-9-]{8,}");
// Get the hub
$usbHub = "";
$serialFound = False;
foreach($line, $logFileContent, <crlf>, "e") {
if ($serialFound == True) {
if (regexmatches($line, "^USB Port Name old")) {
$usbHub = gettoken(gettoken($line, 2, "=", "t"), -2, "-", , 1);
break;
}
}
if (regexmatches($line, "^Volume Serial")) {
if ($srcSerial == gettoken($line, 2, "=", "t")) { $serialFound = True; }
}
}
return $usbHub;
}