Physical vs logical drives in Windows and Lazarus lazarus / 34-Windows ---------------------------------------------------------------------- pusuni · 2016-05-17 12:56 My system: C -> SSD D and E -> HD (the same physical drive) Is there any manner to detect if the logical drives D and E are in the same physical drive or not, in Lazarus? Thanks in advanced ---------------------------------------------------------------------- wp · 2016-05-17 13:40 I found this code on https://www.eldos.com/forum/read.php?FID=16&TID=6004&MID=33475, it is Windows-only (tested with Win10), but it hopefully does what you need: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Windows,  SysUtils,  ActiveX,  ComObj,  Variants; function ListDrives : string;var  FSWbemLocator  : Variant;  objWMIService  : Variant;  colDiskDrives  : Variant;  colLogicalDisks: Variant;  colPartitions  : Variant;  objdiskDrive   : OLEVariant;  objPartition   : OLEVariant;  objLogicalDisk : OLEVariant;  oEnumDiskDrive : IEnumvariant;  oEnumPartition : IEnumvariant;  oEnumLogical   : IEnumvariant;  iValue         : pULONG;  DeviceID       : widestring;  s : widestring;  n: LongWord;begin;  Result:='';  FSWbemLocator   := CreateOleObject('WbemScripting.SWbemLocator');  objWMIService   := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '');  colDiskDrives   := objWMIService.ExecQuery('SELECT DeviceID FROM Win32_DiskDrive', 'WQL');  oEnumDiskDrive  := IUnknown(colDiskDrives._NewEnum) as IEnumVariant;  while oEnumDiskDrive.Next(1, objdiskDrive, n) = 0 do  begin    Writeln(Format('DeviceID %s',[string(objdiskDrive.DeviceID)]));    //Escape the `\` chars in the DeviceID value because the '\' is a reserved character in WMI.    DeviceID        := StringReplace(objdiskDrive.DeviceID,'\','\\',[rfReplaceAll]);    //link the Win32_DiskDrive class with the Win32_DiskDriveToDiskPartition class    s:=Format('ASSOCIATORS OF {Win32_DiskDrive.DeviceID="%s"} WHERE AssocClass = Win32_DiskDriveToDiskPartition',[DeviceID]);    colPartitions   := objWMIService.ExecQuery(s, 'WQL');    oEnumPartition  := IUnknown(colPartitions._NewEnum) as IEnumVariant;    while oEnumPartition.Next(1, objPartition, n) = 0 do    begin      if not VarIsNull(objPartition.DeviceID) then      begin        Writeln(Format('   Partition %s',[string(objPartition.DeviceID)]));      //link the Win32_DiskPartition class with theWin32_LogicalDiskToPartition class.        s:='ASSOCIATORS OF {Win32_DiskPartition.DeviceID="'+VarToStr(objPartition.DeviceID)+'"} WHERE AssocClass = Win32_LogicalDiskToPartition';        colLogicalDisks := objWMIService.ExecQuery(s);        oEnumLogical  := IUnknown(colLogicalDisks._NewEnum) as IEnumVariant;        while oEnumLogical.Next(1, objLogicalDisk, n) = 0 do        begin          Writeln(Format('     Logical Disk %s',[string(objLogicalDisk.DeviceID)]));          objLogicalDisk:=Unassigned;        end;      end;      objPartition:=Unassigned;    end;    objdiskDrive:=Unassigned;  end;end; begin  try    // CoInitialize(nil); Needed for Delphi but not Freepascal    try      ListDrives;    finally     // CoUninitialize;  Needed for Delphi but not Freepascal    end;  except    on E:EOleException do       Writeln(E.Message + '  Code '+IntToStr(E.ErrorCode));    on E:Exception do       Writeln(E.Classname, ':', E.Message);  end;  Writeln('Done');  Readln;end. ---------------------------------------------------------------------- pusuni · 2016-05-18 06:43 Thanks a lot for the info. ---------------------------------------------------------------------- pusuni · 2016-05-18 18:48 Today I've tried to compiler the code in lazarus and it doesn't work properly. The lines Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   objdiskDrive   : OLEVariant;  objPartition   : OLEVariant;  objLogicalDisk : OLEVariant; are faulty. Lazarus complains about OLEVariant: it doesn't exist this data type . The same code, I compiled  in Free Pascal, is faulty, too.  I had to change the lines like QuoteIUnknown(XXX) as IEnumVariant   --> IEnumVariant(XXX) and I deleted the try / except at the end (I don't understand why "try" was not recognized by Free Pascal ) , and the code works properly Any suggestions? Best Regards ---------------------------------------------------------------------- molly · 2016-05-18 19:38 @pusuni which version of lazarus, but more importantly Free Pascal are you using ? It compiles fine with FPC 3.0, although i had to add {$MODE OBJFPC} The only 'warning' i got using OleVariant in a standalone declaration is that the variants unit is used implicitly: "oleole.pas(10) Warning: Implicit uses of Variants unit" Compilling with 2.6.4 got me some errors, but those were more related to windows and its use of some strange (incompatible) types. ---------------------------------------------------------------------- wp · 2016-05-18 20:40 I had tested with Laz trunk/fpc 3.0. Repeating with Laz 1.6/fpc3.0 is fine as well. Laz 1.44/fpc2.6.4, however, yields some compiler errors regarding OLEVariant and LongWord variables - just adapt the variable declarations to what the compiler requires, and then the program runs fine also in this tool combination. The same with Laz 1.2.6/fpc 2.6.4. Did not test older versions, please update in this case. ---------------------------------------------------------------------- pusuni · 2016-05-19 08:44 Quote from: wp on May 18, 2016, 10:40:19 pmI had tested with Laz trunk/fpc 3.0. Repeating with Laz 1.6/fpc3.0 is fine as well. Laz 1.44/fpc2.6.4, however, yields some compiler errors regarding OLEVariant and LongWord variables - just adapt the variable declarations to what the compiler requires, and then the program runs fine also in this tool combination. The same with Laz 1.2.6/fpc 2.6.4. Did not test older versions, please update in this case. I tested with that version: Laz 1.44/fpc2.6.4. I tested with FPC 3.0, too QuoteIt compiles fine with FPC 3.0, although i had to add {$MODE OBJFPC} I did not know he had to add that code. Thanks again