远程 WMI 调用磁盘序列号

发布于 2024-12-28 17:07:21 字数 2022 浏览 0 评论 0原文

我是一个相对缺乏经验的编码员,并且在通过 VBScript 远程获取物理磁盘序列号时遇到了问题。

目前我正在使用 Scriptomatic V2 中由脚本专家提供的默认脚本。我从 2003 服务器运行它并尝试从 Win2000 和 WinXP SP2/SP3 系统获取信息。我从几个教程中看到推荐的 WMI 类是 Win32_PhysicalMedia。

包括有用的位:

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("STN_XP","STN_2000")
  For Each strComputer In arrComputers
    WScript.Echo
    WScript.Echo "=========================================="
    WScript.Echo "Computer: " & strComputer
    WScript.Echo "=========================================="

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMedia", "WQL", _
                                      wbemFlagReturnImmediately + wbemFlagForwardOnly)

    For Each objItem In colItems
      '(Removed a couple from the code, just showing the useful ones)
      WScript.Echo "Model: " & objItem.Model
      WScript.Echo "Name: " & objItem.Name
      WScript.Echo "SerialNumber: " & objItem.SerialNumber
      WScript.Echo "Tag: " & objItem.Tag
      WScript.Echo
      Next
    Next

现在我得到的输出如下: 请注意,这是通过所有调用运行脚本的确切输出;除了 objItem.Tag 值之外,没有返回任何数据:

==========================================
Computer: STN_XP
==========================================
Capacity:
Caption:
CleanerMedia:
CreationClassName:
Description:
HotSwappable:
Manufacturer:
MediaDescription:
MediaType:
Model:
Name:
OtherIdentifyingInfo:
PartNumber:
PoweredOn:
Removable:
Replaceable:
SerialNumber:
SKU:
Status:
Tag: \\.\PHYSICALDRIVE0
Version:
WriteProtectOn:

==========================================
Computer: STN_2000
==========================================

所有计算机都连接到域,我登录到主管理员帐户。使用其他一些 WMI 库,我获取数据,并且到目前为止,我在一台特定计算机上收到了序列号(和标签,但没有其他内容)。我已经了解到这是 Vista 的一个问题,您需要在管理员模式下运行。由于所使用的操作系统,这在这里不应该成为问题。有人知道可能出了什么问题吗?

作为后续问题,有谁知道如何从 2000 站获取序列号?

预先感谢您能给我的任何帮助。

I'm a relatively inexperienced coder and I've been running into an issue with getting the physical disk serial number remotely via a VBScript.

Currently I'm using the default script in Scriptomatic V2, by the Scripting Guys. I'm running it from a 2003 Server and trying to get info from Win2000 and WinXP SP2/SP3 systems. I've seen from a couple tutorials that the WMI class recommended is Win32_PhysicalMedia.

Including the useful bits:

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("STN_XP","STN_2000")
  For Each strComputer In arrComputers
    WScript.Echo
    WScript.Echo "=========================================="
    WScript.Echo "Computer: " & strComputer
    WScript.Echo "=========================================="

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMedia", "WQL", _
                                      wbemFlagReturnImmediately + wbemFlagForwardOnly)

    For Each objItem In colItems
      '(Removed a couple from the code, just showing the useful ones)
      WScript.Echo "Model: " & objItem.Model
      WScript.Echo "Name: " & objItem.Name
      WScript.Echo "SerialNumber: " & objItem.SerialNumber
      WScript.Echo "Tag: " & objItem.Tag
      WScript.Echo
      Next
    Next

Now the output I get is below: Note this is the exact output from running the script with all calls; no data is returned beyond the objItem.Tag value:

==========================================
Computer: STN_XP
==========================================
Capacity:
Caption:
CleanerMedia:
CreationClassName:
Description:
HotSwappable:
Manufacturer:
MediaDescription:
MediaType:
Model:
Name:
OtherIdentifyingInfo:
PartNumber:
PoweredOn:
Removable:
Replaceable:
SerialNumber:
SKU:
Status:
Tag: \\.\PHYSICALDRIVE0
Version:
WriteProtectOn:

==========================================
Computer: STN_2000
==========================================

All computers are connected to a domain, I'm logged in to the primary admin account. Using some of the other WMI libraries, I get data, and on one specific computer so far I've received a serial number (and tag, but nothing else). I've read up on this being an issue for Vista, where you are required to run in admin mode. This shouldn't be an issue here, due to the OSes in use. Anyone know what might be wrong?

As a follow-up question, does anyone know how to get the Serial Number from a 2000 station?

Thanks in advance for any help you can give me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

下雨或天晴 2025-01-04 17:07:21

用单引号注释掉 On Error Resume Next,并发布可能返回的错误消息。

Comment out the On Error Resume Next with a single quote, and post the error message that is likely being returned.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文