The following is a master to help write the code but get a little mistakes in my computer, and could not contact him so please cow elder brothers here help
Failed to get to my F plate is under which hard disk and partition is I get to the screenshot
The following is the code:
Uses the ActiveX, ComObj;
The function ListDrives: string;
Var
FSWbemLocator: OLEVariant;
ObjWMIService: OLEVariant;
ColDiskDrives: OLEVariant;
ColLogicalDisks: OLEVariant;
ColPartitions: OLEVariant;
ObjdiskDrive: OLEVariant;
ObjPartition: OLEVariant;
ObjLogicalDisk: OLEVariant;
OEnumDiskDrive: IEnumvariant;
OEnumPartition: IEnumvariant;
OEnumLogical: IEnumvariant;
IValue: LongWord;
DeviceID: string;
The begin.
Result:=';
FSWbemLocator:=CreateOleObject (' WbemScripting. SWbemLocator ');
ObjWMIService:=FSWbemLocator ConnectServer (' localhost ', 'root \ CIMV2', ', ');
ColDiskDrives:=objWMIService ExecQuery (' SELECT DeviceID FROM Win32_DiskDrive ');
OEnumDiskDrive:=IUnknown (colDiskDrives _NewEnum) as IEnumVariant;
While oEnumDiskDrive. Next (1, objdiskDrive, iValue)=0 do
The begin
Form1. Memo1. Lines. The Add (Format (' DeviceID % s', [string (objdiskDrive. DeviceID)]));
DeviceID:=StringReplace (objdiskDrive DeviceID, '\' \ '\', [rfReplaceAll]);
ColPartitions:=objWMIService ExecQuery (Format (' ASSOCIATORS OF {Win32_DiskDrive. DeviceID="% s"} WHERE AssocClass=Win32_DiskDriveToDiskPartition ', [DeviceID]));
OEnumPartition:=IUnknown (colPartitions _NewEnum) as IEnumVariant;
While oEnumPartition. Next (1, objPartition, iValue)=0 do
The begin
If not VarIsNull (objPartition. DeviceID) then
The begin
Form1. Memo1. Lines. The Add (Format (' Partition % s', [string (objPartition. DeviceID)]));
ColLogicalDisks:=objWMIService ExecQuery (ASSOCIATORS 'OF {Win32_DiskPartition. DeviceID="' + VarToStr (objPartition. DeviceID) + '"} WHERE AssocClass=Win32_LogicalDiskToPartition');
OEnumLogical:=IUnknown (colLogicalDisks _NewEnum) as IEnumVariant;
While oEnumLogical. Next (1, objLogicalDisk, iValue)=0 do
The begin
Form1. Memo1. Lines. The Add (Format (' Logical Disk % s', [string (objLogicalDisk. DeviceID)]));
ObjLogicalDisk:=the Unassigned;
end;
end;
ObjPartition:=the Unassigned;
end;
ObjdiskDrive:=the Unassigned;
end;
end;
Procedure TForm1. Button1Click (Sender: TObject);
The begin
Try
CoInitialize (nil);
Try
ListDrives;
The finally
CoUninitialize;
end;
Except,
On E: the Exception do
Form1. Memo1. Lines. The Add (e.c. with our fabrication: lassname + ', '+ E.M essage);
end;
end;
CodePudding user response:
Seek expert help under your topCodePudding user response:
Actually drive F output, as to why the dislocation, temporarily don't see reason,CodePudding user response: