Home > Back-end >  Seek expert help modify the WMI code section of Delphi call
Seek expert help modify the WMI code section of Delphi call

Time:09-27

Each code for current which is the main purpose of hard disk hard disk partition and obtain partition ID such as:


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 top

CodePudding user response:

Actually drive F output, as to why the dislocation, temporarily don't see reason,

CodePudding user response:

refer to the second floor pathletboy response:
actually drive F output, as to why dislocation, temporarily don't see reason,

Because I am using Windows 7 system with 100 m reserves estimates 0 that is retained by partitioning

CodePudding user response:

Win32_Volume can get ready to even shows the Windows 7 reserve system but can't seem to use this parameter under XP help you a great god!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  • Related