ManagementObject 初始化失败
为了获得卷序列号,我编写了一个如下所示的函数:
string drive = Environment.ExpandEnvironmentVariables("%SystemDrive%").Replace(":", "");
string id = getVolumeSerial(drive);
private static string getVolumeSerial(string drive)
{
ManagementObject disk = new ManagementObject(@"win32_logicaldisk.deviceid="""
+ drive + @":""");
disk.Get();
string volumeSerial = disk["VolumeSerialNumber"].ToString();
disk.Dispose();
return volumeSerial;
}
我将包含该函数的软件部署给 30 个人,但在 31 人的计算机上, ManagementObject 的初始化失败并抛出异常。是否有更好/替代/更可靠的方法来获取卷序列号?
In order to get the volume serial I wrote a function that looks like that:
string drive = Environment.ExpandEnvironmentVariables("%SystemDrive%").Replace(":", "");
string id = getVolumeSerial(drive);
private static string getVolumeSerial(string drive)
{
ManagementObject disk = new ManagementObject(@"win32_logicaldisk.deviceid="""
+ drive + @":""");
disk.Get();
string volumeSerial = disk["VolumeSerialNumber"].ToString();
disk.Dispose();
return volumeSerial;
}
I deployed the software containing that to 30 people but at 31's computer the init of ManagementObject fails and thows an exception. Are there better / alternative / more reliable ways to get the volume serial no?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论