...
「很難說沒有看到所有的 相關的代碼和聲明「。
但是沒有更多相關的代碼! ,我已經改變了下面的代碼:
procedure TUSBItem.GetInfo;
var
WMIService : OLEVariant;
DItems, PItems, LItems, VItems: OLEVariant;
Drive, Partition, Logical, Volume : OLEVariant;
Drives, Partitions, Logicals, Volumes : IEnumVARIANT;
IValue : LongWord;
begin
WMIService := GetWMIObject('winmgmts:\\localhost\root\cimv2');
DItems := WMIService.ExecQuery('select DeviceID, Model from Win32_DiskDrive where InterfaceType='+QuotedStr('USB'));
Drives := IUnKnown(DItems._NewEnum) as IEnumVARIANT;
while Drives.Next(1, Drive, IValue) = S_OK do
begin
DeviceID := Drive.Properties_.Item('DeviceID', 0);
PItems := WMIService.ExecQuery('associators of {{Win32_DiskDrive.DeviceID='+QuotedStr(DeviceID)+'}} where AssocClass = Win32_DiskDriveToDiskPartition');
Partitions := IUnKnown(PItems._NewEnum) as IEnumVARIANT;
if Partitions.Next(1, Partition, IValue) = S_OK then
begin
if not VarIsNull(Partition) then
PDeviceID := Partition.Properties_.Item('DeviceID', 0);
end;
...
end;
...
end;
在雖然循環,在驅動器枚舉變型,各驅動器,我得到一個「的DeviceID」,我應該通過「的DeviceID」陳述「的社員」到作爲查詢的結果獲得與驅動器相關聯的分區列表「DeviceID」...
在下一行中,我把PItems分區作爲IEnumVARIANT,接下來我檢查是否將分區的第一個元素放入分區「S_OK」(成功!)然後我檢查分區,如果它不是名爲「DeviceID」的項目,但在這一行中,我收到一條錯誤消息:「無效的Va riant操作「
有相同的方式來獲取驅動器的DeviceID和分區的DeviceID,但是當我想要獲得分區的DeviceID我得到一個錯誤,他們之間有一個不同和它的查詢WMI,我猜問題是,但我不確定!
有一些有用的句子:
「然而,你應該寫你的架構供應商時,請記住以下幾點:
* Make sure you support standard queries in your association class, especially queries where the reference properties are used in a WHERE clause. For more information, see CFrameworkQuery::GetValuesForProp.
* In your association class support, when you check to see if the endpoints exist, ensure you use the CWbemProviderGlue::GetInstanceKeysByPath or CWbemProviderGlue::GetInstancePropertiesByPath methods.
These methods allow the endpoints to skip populating expensive or unneeded properties.
* Make sure any association endpoint classes support per-property Get methods. For more information, see Supporting Partial-Instance Operations. For more information about the query parameter, see CFrameworkQuery. **"**
,因爲這可以解釋,我覺得現在的問題是路徑!,意思是我應該給我的目標(這裏是分區)到WMIService對象來得到結果!, there is some help它,但我完全困惑!
在
Source page
當然,我將其轉換,isn`t任何關於路徑解釋...!
非常感謝...