Win32_PhysicalMedia不会为Windows 7返回一致/相同的硬盘序列号 [英] Win32_PhysicalMedia not returning consistent/same Hard Disk Serial Number for Windows 7
问题描述
我正在Windows 7中使用Win32_PhysicalMedia读取硬盘序列号.通常它返回错误的序列号.此问题不一致.
i am using Win32_PhysicalMedia in windows 7 for reading the Hard Disk Serial Number. Often it returns the wrong serial number.This problem is inconsistent .
仅在很少的Windows 7计算机中会出现此问题.
This problem arises only in few Windows 7 machine.
对于Windows XP,相同的逻辑总是可以正常工作.
The same logic always works fine for Windows XP.
我使用的代码段如下:-
the code snippet, which i have used is below :-
字符串键="Win32_PhysicalMedia";
ManagementObjectSearcher搜索程序=新的ManagementObjectSearcher("从" +键中选择*);
字符串SerialNumber = string.Empty;
试试
{
字符串项目= string.Empty;
foreach(ManagementObject在searcher.Get()中的共享)
{
如果(share.Properties.Count< = 0)
{
b返回";
}
object SerNumber = share ["SerialNumber"];
如果(SerNumber!= null)
{
b SerialNumber = share ["SerialNumber"].ToString().Trim();
b休息;
}
//foreach(共享的PropertyDataPC.Properties)
//{
// if(PC!= null&& PC.Value!= null)
// {
// item = PC.Name;
// if(item =="SerialNumber")
// {
// SerialNumber = SerialNumber +(PC.Value.ToString()).Trim();
// }
// }
//}
}
string Key = "Win32_PhysicalMedia";
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + Key);
string SerialNumber = string.Empty;
try
{
string item = string.Empty;
foreach (ManagementObject share in searcher.Get())
{
if (share.Properties.Count <= 0)
{
return "";
}
object SerNumber = share["SerialNumber"];
if (SerNumber != null)
{
SerialNumber = share["SerialNumber"].ToString().Trim();
break;
}
//foreach (PropertyData PC in share.Properties)
//{
// if (PC != null && PC.Value != null)
// {
// item = PC.Name;
// if (item == "SerialNumber")
// {
// SerialNumber = SerialNumber + (PC.Value.ToString()).Trim();
// }
// }
//}
}
该代码一读取一个序列号(或第一个序列号),便立即存在.
As soon as the code read a Serial Number ( or First Serial Number) , it exists.
在这方面请提供帮助.
推荐答案
谢谢您的发帖!我建议您将您的问题发布到论坛上
Thank you for your post! I would suggest please post your question in the forum
Windows >
Windows > Windows Forums > Windows 7 Forums
位于此处: http://social.answers.microsoft.com/Forums/zh-CN/category/windows7
located here: http://social.answers.microsoft.com/Forums/en-US/category/windows7
祝你有美好的一天!!!!!
Have a great day!!!!!
这篇关于Win32_PhysicalMedia不会为Windows 7返回一致/相同的硬盘序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!