如何获取 WbemScripting 查询返回的列的名称?
我有以下过程来运行 WMI 查询,并且效果非常好。
procedure TFormMain.GetWMIOSInfo(const RemoteMachine, Username, Password: string);
var
FSWbemLocator: OLEVariant;
FWMIService: OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject: OLEVariant;
oEnum: IEnumvariant;
iValue: LongWord;
begin;
try
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer(RemoteMachine, 'root\CIMV2', Username, Password);
FWbemObjectSet := FWMIService.ExecQuery(
'select screenwidth, screenheight, status from Win32_DesktopMonitor','WQL', 0);
try
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
Listbox1.Items.Add(
VarToStr(FWbemObject.availability) + ', ' +
VarToStr(FWbemObject.screenwidth) + ', ' +
VarToStr(FWbemObject.screenheight));
FWbemObject := Unassigned;
end;
finally
FWbemObjectSet := Unassigned;
end;
Except on E: Exception do
Raise;
end;
end;
我想更改查询以返回所有字段,例如 select * from Win32_DesktopMonitor
。我的问题是我不知道如何确定 FWbemObject
中查询返回的列的名称。 IE。我想枚举 FWbemObject
中的列。
Listbox1.Items.Add(
VarToStr(FWbemObject.<?>) + ', ' +
VarToStr(FWbemObject.<?>) + ', ' +
....
VarToStr(FWbemObject.<?>));
I have the following procedure to run a WMI query, and it works perfectly well.
procedure TFormMain.GetWMIOSInfo(const RemoteMachine, Username, Password: string);
var
FSWbemLocator: OLEVariant;
FWMIService: OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject: OLEVariant;
oEnum: IEnumvariant;
iValue: LongWord;
begin;
try
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer(RemoteMachine, 'root\CIMV2', Username, Password);
FWbemObjectSet := FWMIService.ExecQuery(
'select screenwidth, screenheight, status from Win32_DesktopMonitor','WQL', 0);
try
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
Listbox1.Items.Add(
VarToStr(FWbemObject.availability) + ', ' +
VarToStr(FWbemObject.screenwidth) + ', ' +
VarToStr(FWbemObject.screenheight));
FWbemObject := Unassigned;
end;
finally
FWbemObjectSet := Unassigned;
end;
Except on E: Exception do
Raise;
end;
end;
I would like to alter the query to return all the fields like select * from Win32_DesktopMonitor
. My problem is that I do not know how to determine the names of the columns that are returned by the query in FWbemObject
. ie. I'd like to enumerate the columns in the FWbemObject
.
Listbox1.Items.Add(
VarToStr(FWbemObject.<?>) + ', ' +
VarToStr(FWbemObject.<?>) + ', ' +
....
VarToStr(FWbemObject.<?>));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Pieter,您必须使用
SWbemObject.Properties_
的属性SWbemObject
对象。检查这个样本。
Pieter you must use the
SWbemObject.Properties_
Property of theSWbemObject
Object.check this sample.
SWbemObject
接口公开Properties_
属性,它是一个集合(因此您可以通过与枚举
ExecQuery
返回的SWebmObjectSet
接口相同的方式来枚举它)。此集合的项目是 SWbemProperty公开Name
和Value
属性的接口。The
SWbemObject
interface exposes theProperties_
property which is a collection (so you can enumerate it probably in the same way as you enumerate theSWebmObjectSet
interface returned byExecQuery
). The items of this collection are SWbemProperty interfaces which exposeName
andValue
properties.