쩝.. 자답입니다. MSDN에 다 있네요 ㅜㅜ
난잡이며..... 나오는것까미나 본다고 막 한것이니.... 욕하지 마세요 &&
CDROM은 이제 해봐야겠네요.
<!--CodeS-->
procedure TForm3.Button2Click(Sender: TObject);
var
intC, intD : integer;
tmpStr : string;
pStrings : TStrings;
tmpStrings : TStrings;
intPhyicalDeviceIdx : integer;
intPartitionDeviceIdx : integer;
pNode, pNodeDrive : TTreeNode;
function getCaptionToIdx( zListView : TListView; zValue : string ) : integer;
var
intC : integer;
begin
for intC := 0 to zListView.Items.Count - 1 do
if (strComp( pChar( upperCase( zListView.Items[ intC ].Caption ) ), pChar( upperCase( zValue ) ) ) = 0) then begin
result := intC;
exit;
end;
end;
function getDeviceIDToNode( zTreeView : TTreeView; zValue : string ) : TTreeNode;
var
intC : integer;
pStrings : TStrings;
begin
result := nil;
for intC := 0 to (zTreeView.Items.Count - 1) do begin
if (zTreeView.Items[ intC ].Level = 0) then begin
pStrings := zTreeView.Items[ intC ].Data;
if (strComp( pChar( upperCase( pStrings.Values[\'DeviceID\'] ) ), pChar( upperCase( zValue ) ) ) = 0) then begin
result := zTreeView.Items[ intC ];
exit;
end;
end;
end;
end;
begin
proResult( ListView1, \'Win32_DiskDrive\' );
for intC := 0 to (ListView1.Columns.Count - 2) do begin
pStrings := TSTringList.Create;
pStrings.Values[\'Model\'] := ListView1.Items[ getCaptionToIdx(ListView1, \'Model\') ].SubItems.Strings[ intC ];
pStrings.Values[\'DeviceID\'] := RightStr( ListView1.Items[ getCaptionToIdx(ListView1, \'DeviceID\') ].SubItems.Strings[ intC ], Length( ListView1.Items[ getCaptionToIdx(ListView1, \'DeviceID\') ].SubItems.Strings[ intC ] ) - 4);
TreeView1.Items.AddObject( nil, ListView1.Items[ getCaptionToIdx(ListView1, \'Caption\') ].SubItems.Strings[ intC ], pStrings );
end;
proResult( ListView1, \'Win32_DiskDriveToDiskPartition\' );
for intC := 0 to (ListView1.Columns.Count - 2) do begin
pStrings := TSTringList.Create;
tmpStrings := TStringList.Create;
tmpStrings.Delimiter := \'\\\';
tmpStrings.StrictDelimiter := true;
tmpStrings.DelimitedText := ListView1.Items[ getCaptionToIdx(ListView1, \'Antecedent\') ].SubItems.Strings[ intC ];
pStrings.Values[\'Antecedent\'] := LeftStr( tmpStrings.Strings[ tmpStrings.Count - 1 ], Length( tmpStrings.Strings[ tmpStrings.Count - 1 ] ) - 1);
tmpStrings.Delimiter := \'\"\';
tmpStrings.StrictDelimiter := true;
tmpStrings.DelimitedText := ListView1.Items[ getCaptionToIdx(ListView1, \'Dependent\') ].SubItems.Strings[ intC ];
pStrings.Values[\'Dependent\'] := tmpStrings.Strings[ tmpStrings.Count - 2 ];
pStrings.Values[\'Dependent\'] := StringReplace( pStrings.Values[\'Dependent\'], \' \', \'\', [rfReplaceAll]);
pStrings.Values[\'Dependent\'] := StringReplace( pStrings.Values[\'Dependent\'], \'#\', \'-\', [rfReplaceAll]);
pNode := getDeviceIDToNode( TreeView1, pStrings.Values[\'Antecedent\'] );
TreeView1.Items.AddChildObject( pNode, pStrings.Values[\'Dependent\'], pStrings );
end;
proResult( ListView1, \'Win32_LogicalDiskToPartition\' );
for intC := 0 to (ListView1.Columns.Count - 2) do begin
pStrings := TSTringList.Create;
tmpStrings := TStringList.Create;
tmpStrings.Delimiter := \'\"\';
tmpStrings.StrictDelimiter := true;
tmpStrings.DelimitedText := ListView1.Items[ getCaptionToIdx(ListView1, \'Antecedent\') ].SubItems.Strings[ intC ];
pStrings.Values[\'Antecedent\'] := tmpStrings.Strings[ tmpStrings.Count - 2 ];
pStrings.Values[\'Antecedent\'] := StringReplace( pStrings.Values[\'Antecedent\'], \' \', \'\', [rfReplaceAll]);
pStrings.Values[\'Antecedent\'] := StringReplace( pStrings.Values[\'Antecedent\'], \'#\', \'-\', [rfReplaceAll]);
tmpStrings.Delimiter := \'\"\';
tmpStrings.StrictDelimiter := true;
tmpStrings.DelimitedText := ListView1.Items[ getCaptionToIdx(ListView1, \'Dependent\') ].SubItems.Strings[ intC ];
pStrings.Values[\'Dependent\'] := tmpStrings.Strings[ tmpStrings.Count - 2 ];
tmpStrings.Delimiter := \',\';
tmpStrings.StrictDelimiter := true;
tmpStrings.DelimitedText := pStrings.Values[\'Antecedent\'];
tmpStr := tmpStrings.Strings[ 0 ];
intPhyicalDeviceIdx := strToint( RightStr( tmpStr, Length( tmpStr ) - Pos( \'-\', tmpStr ) ) );
tmpStr := tmpStrings.Strings[ 1 ];
intPartitionDeviceIdx := strToint( RightStr( tmpStr, Length( tmpStr ) - Pos( \'-\', tmpStr ) ) );
pNode := getDeviceIDToNode( TreeView1, \'physicaldrive\' + IntToStr( intPhyicalDeviceIdx ) );
if Assigned( pNode ) then begin
for intD := 0 to (pNode.Count - 1) do begin
if (pNode.Item[ intD ].Text = pStrings.Values[\'Antecedent\']) then begin
try
TreeView1.Items.AddChild( pNode.Item[ intD ], pStrings.Values[\'Dependent\'] );
except
on e : Exception do begin
showMessage( pNode.Item[ intD ].Text );
end;
end;
end;
end;
end;
end;
end;
<!--CodeE-->