如何加入 WMI 查询 (WQL)
我想通过 WQL 查询获取启动硬盘的序列号。
可以使用以下查询检索引导分区:
SELECT * FROM Win32_DiskPartition where BootPartition=True
序列号位于 Win32_DiskDrive 中:
SELECT DeviceID, SerialNumber FROM Win32_DiskDrive
Win32_DiskDriveToDiskPartition
具有 Win32_DiskDrive
到 Win32_DiskPartition
的映射。 它们在 Win32_DiskDriveToDiskPartition
中将 Win32_DiskDrive.DeviceID
映射到 Win32_DiskPartition.DeviceID
如何构建内部联接 Win32_DiskPartition
的 WQL 查询> 和Win32_DiskDrive
? 我必须使用关联器还是它可以与 INNER JOIN 一起使用?
I want to get the serial number of the boot-harddisk via a WQL query.
The boot-partition can be retrieved using the following query:
SELECT * FROM Win32_DiskPartition where BootPartition=True
The serial number is in Win32_DiskDrive:
SELECT DeviceID, SerialNumber FROM Win32_DiskDrive
Win32_DiskDriveToDiskPartition
has the mapping of Win32_DiskDrive
to Win32_DiskPartition
.
They are mapped Win32_DiskDrive.DeviceID
to Win32_DiskPartition.DeviceID
in Win32_DiskDriveToDiskPartition
How can I build a WQL query that inner joins Win32_DiskPartition
and Win32_DiskDrive
?
Do I have to use Associators or does it work with INNER JOIN?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WQL 不支持
JOIN
子句。正如您所猜测的,您需要使用 ASSOCIATORS OF 语句。以下是 VBScript 中的示例:但请注意,
Win32_DiskDrive.SerialNumber
属性在 Windows Vista 之前不可用。因此,如果您希望代码也能在早期 Windows 版本(例如 Windows XP 或 Windows 2000)上运行,您应该考虑使用 WMI 以外的 API。编辑:(回复评论)是的,您可以添加嵌套的
ASSOCIATORS OF
查询来获取Win32_PhysicalMedia
实例对应于Win32_DiskDrive
实例;像这样的事情:你还没有说你正在使用什么语言 - 我想在 PowerShell 或 C# 中,整个事情可以更优雅地完成,但 VBScript 相当冗长。
WQL doesn't support the
JOIN
clause. You need to use theASSOCIATORS OF
statement as you guessed. Here's an example in VBScript:Note, however, that the
Win32_DiskDrive.SerialNumber
property isn't available prior to Windows Vista. So, if you want your code to work on earlier Windows versions as well (e.g. Windows XP or Windows 2000) you should consider using APIs other than WMI.Edit: (reply to comment) Yes, you can add a nested
ASSOCIATORS OF
query to get theWin32_PhysicalMedia
instances corresponding to theWin32_DiskDrive
instances; something like this:You haven't said what language you're using - I guess in PowerShell or C# the whole thing can be done more elegantly, but VBScript is pretty verbose.
下面是与 Helen 发布的 VBScript 代码执行相同操作的 C++ 代码。
Here is the C++ code that does the same thing as the VBScript code posted by Helen.