必须进行实验才能从WMI中提取复杂的信息。我试图在我的电脑上找到并行端口地址,报告如下:
首先,我查询了win32_parallelport类以查找所有并行端口。(使用与之前发布的pruz相同的代码):'select*from win32_parallelport'。结果是(我的系统中只有一个并行端口):
instance of Win32_ParallelPort
{
Availability = 3;
Caption = "LPT1";
ConfigManagerErrorCode = 0;
ConfigManagerUserConfig = FALSE;
CreationClassName = "Win32_ParallelPort";
Description = "LPT1";
DeviceID = "LPT1";
Name = "LPT1";
OSAutoDiscovered = TRUE;
PNPDeviceID = "ACPI\\PNP0401\\4&25C6B52A&0";
PowerManagementSupported = FALSE;
ProtocolSupported = 17;
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "JUPITER";
};
其次,我查询了win32 pnpallocatedResource(‘select*from win32 pnpallocatedResource’)。我在这里有很多信息,但我只选择了pNPdeviceID=“acpi\pnp0401\4&25c6b52a&0”的3个条目。
instance of Win32_PNPAllocatedResource
{
Antecedent = "\\\\JUPITER\\root\\cimv2:Win32_PortResource.StartingAddress=\"888\"";
Dependent = "\\\\JUPITER\\root\\cimv2:Win32_PnPEntity.DeviceID=\"ACPI\\\\PNP0401\\\\4&25C6B52A&0\"";
};
instance of Win32_PNPAllocatedResource
{
Antecedent = "\\\\JUPITER\\root\\cimv2:Win32_PortResource.StartingAddress=\"1912\"";
Dependent = "\\\\JUPITER\\root\\cimv2:Win32_PnPEntity.DeviceID=\"ACPI\\\\PNP0401\\\\4&25C6B52A&0\"";
};
instance of Win32_PNPAllocatedResource
{
Antecedent = "\\\\JUPITER\\root\\cimv2:Win32_DMAChannel.DMAChannel=3";
Dependent = "\\\\JUPITER\\root\\cimv2:Win32_PnPEntity.DeviceID=\"ACPI\\\\PNP0401\\\\4&25C6B52A&0\"";
};
第三项不感兴趣。前两个条目给我们两个(十进制)起始地址(888和1912)
最后,我查询了win32_portresource(“select*from win32_portresource”)以查找与起始地址888和1912对应的结束地址:
instance of Win32_PortResource
{
Alias = FALSE;
Caption = "0x00000378-0x0000037F";
CreationClassName = "Win32_PortResource";
CSCreationClassName = "Win32_ComputerSystem";
CSName = "JUPITER";
Description = "0x00000378-0x0000037F";
EndingAddress = "895";
Name = "0x00000378-0x0000037F";
StartingAddress = "888";
Status = "OK";
};
instance of Win32_PortResource
{
Alias = FALSE;
Caption = "0x00000778-0x0000077B";
CreationClassName = "Win32_PortResource";
CSCreationClassName = "Win32_ComputerSystem";
CSName = "JUPITER";
Description = "0x00000778-0x0000077B";
EndingAddress = "1915";
Name = "0x00000778-0x0000077B";
StartingAddress = "1912";
Status = "OK";
};
更新的
我在GUI应用程序中使用了与rruz相同的代码(见下文)。唯一需要编译的是wbemscripting_tlb.pas单元。该单元是由类型库导入向导生成的,您可以在Delphi2009中了解该过程。
my blog
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses WbemScripting_TLB, ActiveX;
{$R *.dfm}
procedure TForm1.Button4Click(Sender: TObject);
var
WMIServices : ISWbemServices;
WMILocator : ISWbemLocator;
Root : ISWbemObjectSet;
SWbemObject : ISWbemObject;
Item : IEnumVariant;
rgVar : OleVariant;
pCelFetched : Cardinal;
begin
Memo1.Lines.Clear;
WMILocator := CoSWbemLocator.Create();
WMIServices := WMILocator.ConnectServer('.', 'root\cimv2','', '', '', '', 0, nil); //
Root := WMIServices.ExecQuery('Select * From Win32_PnPAllocatedResource','WQL', 0, nil);
Item := (Root._NewEnum) as IEnumVariant;
while (Item.Next(1, rgVar, pCelFetched) = S_OK) do
begin
SWbemObject := IUnknown(rgVar) as ISWBemObject;
if (SWbemObject <> nil) then
begin
SWbemObject.Properties_;//Load the Properties to read
Memo1.Lines.Add(SWbemObject.GetObjectText_(0));
end;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
WMIServices : ISWbemServices;
WMILocator : ISWbemLocator;
Root : ISWbemObjectSet;
SWbemObject : ISWbemObject;
Item : IEnumVariant;
rgVar : OleVariant;
pCelFetched : Cardinal;
begin
Memo1.Lines.Clear;
WMILocator := CoSWbemLocator.Create();
WMIServices := WMILocator.ConnectServer('.', 'root\cimv2','', '', '', '', 0, nil); //
Root := WMIServices.ExecQuery('Select * From Win32_PortResource','WQL', 0, nil);
Item := (Root._NewEnum) as IEnumVariant;
while (Item.Next(1, rgVar, pCelFetched) = S_OK) do
begin
SWbemObject := IUnknown(rgVar) as ISWBemObject;
if (SWbemObject <> nil) then
begin
SWbemObject.Properties_;//Load the Properties to read
Memo1.Lines.Add(SWbemObject.GetObjectText_(0));
end;
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
var
WMIServices : ISWbemServices;
WMILocator : ISWbemLocator;
Root : ISWbemObjectSet;
SWbemObject : ISWbemObject;
Item : IEnumVariant;
rgVar : OleVariant;
pCelFetched : Cardinal;
begin
Memo1.Lines.Clear;
WMILocator := CoSWbemLocator.Create();
WMIServices := WMILocator.ConnectServer('.', 'root\cimv2','', '', '', '', 0, nil); //
Root := WMIServices.ExecQuery('Select * From Win32_ParallelPort','WQL', 0, nil);
Item := (Root._NewEnum) as IEnumVariant;
while (Item.Next(1, rgVar, pCelFetched) = S_OK) do
begin
SWbemObject := IUnknown(rgVar) as ISWBemObject;
if (SWbemObject <> nil) then
begin
SWbemObject.Properties_;//Load the Properties to read
Memo1.Lines.Add(SWbemObject.GetObjectText_(0));
end;
end;
end;
end.