wmic 磁盘驱动器获取序列号 ->无效的 xml 输出
我想读取硬盘的名称和序列号。
我偶然发现了 wmic
但我遇到了麻烦。我想这两个命令应该可以解决问题,但我只收到消息:
Invalid Xml-Content. //(Translated)
wmic path win32_physicalmedia get serialnumber
或者
wmic DISKDRIVE GET SerialNumber
我也尝试了以下操作:
wmic DISKDRIVE GET SerialNumber /FORMAT:list
wmic DISKDRIVE GET SerialNumber /FORMAT:xml.xsl
wmic DISKDRIVE GET SerialNumber > c:\test.txt
关于我做错了什么有什么想法吗?
解决方案:
谢谢JPBlanc,通过/?
命令我发现SerialNumber
根本不存在。我现在使用
WMIC /output:"c:\hdds.txt" DISKDRIVE GET PNPDeviceID,Name /Format:CSV
它给出了正确的结果。
I want to read the name and the serial number of my hard drives.
I stumbled upon wmic
but I'm having troubles. I guess these two commands should do the trick, but I only get the message:
Invalid Xml-Content. //(Translated)
wmic path win32_physicalmedia get serialnumber
or
wmic DISKDRIVE GET SerialNumber
I tried the following as well:
wmic DISKDRIVE GET SerialNumber /FORMAT:list
wmic DISKDRIVE GET SerialNumber /FORMAT:xml.xsl
wmic DISKDRIVE GET SerialNumber > c:\test.txt
Any ideas on what I'm doing wrong?
Solution:
Thanks JPBlanc, via the /?
command I've found out that SerialNumber
doesn't even exist. I now use
WMIC /output:"c:\hdds.txt" DISKDRIVE GET PNPDeviceID,Name /Format:CSV
which gives the correct result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在 Windows 7 x86 Pro 上遇到此错误(查询序列号 应该可以)当连接外部驱动器时。
这就是我修复它的方法:
获取每个驱动器的 ID:
wmic diskdrive get deviceid /format:list
解析输出并获取第一个 ID。就我而言,这是
\\.\PHYSICALDRIVE0
转义反斜杠,以便 ID 为
\\\\.\\PHYSICALDRIVE0
使用转义 ID 获取驱动器的序列号:
wmic 磁盘驱动器,其中 deviceid='\\\\.\\PHYSICALDRIVE0' 获取
Serialnumber /format:list
重复步骤 2 - 4,直到获得所有驱动器的序列号
编辑:以上内容不'无法在我的 Windows XP x86 Pro 上运行。
这会:
I was getting this error on Windows 7 x86 Pro (where querying the serial number should be possible) when an external drive was connected.
This is how I fixed it:
Get the ID of each drive:
wmic diskdrive get deviceid /format:list
Parse the output and get the first ID. In my case this was
\\.\PHYSICALDRIVE0
Escape the backslashes so that the ID is
\\\\.\\PHYSICALDRIVE0
Get the serial number of the drive using its escaped ID:
wmic diskdrive where deviceid='\\\\.\\PHYSICALDRIVE0' get
serialnumber /format:list
Repeat steps 2 - 4 until you have the serial numbers of all drives
Edit: The above doesn't work on my copy of Windows XP x86 Pro.
This does:
您只是在使用 WMIC 命令行时犯了一个错误,
WMIC DISKDRIVE GET SerialNumber /Format /?
为您提供了关键字:您可以尝试:
您可以将
RAWXML
替换为其他之一格式。You are just making a mistake usin WMIC command line,
WMIC DISKDRIVE GET SerialNumber /Format /?
gives you keywords:you can try :
You can replace
RAWXML
by one of the others formats.出现此问题的原因是 XML 解析器将某些驱动器序列号中包含的控制字符视为无效。
this issue occurs because the XML parser treats the control characters that are included in the serial number of some drives as invalid.