Fix: Client WMI Serial Number

Potential bug where a NULL serial number could cause an unexpected
error.
See: http://discoict.com.au/forum/support/2013/2/client-error.aspx
This commit is contained in:
Gary Sharp
2013-02-25 11:59:04 +11:00
parent 69c61a9b7d
commit 7b93c17317
+26 -8
View File
@@ -31,9 +31,14 @@ namespace Disco.Client.Interop
{ {
if (mItem != null) if (mItem != null)
{ {
DeviceSerialNumber = mItem.GetPropertyValue("SerialNumber").ToString().Trim(); DeviceSerialNumber = mItem.GetPropertyValue("SerialNumber") as string;
if (!string.IsNullOrEmpty(DeviceSerialNumber))
DeviceSerialNumber = DeviceSerialNumber.Trim();
ErrorReporting.DeviceIdentifier = DeviceSerialNumber; ErrorReporting.DeviceIdentifier = DeviceSerialNumber;
DeviceSMBIOSVersion = mItem.GetPropertyValue("SMBIOSBIOSVersion").ToString().Trim(); DeviceSMBIOSVersion = mItem.GetPropertyValue("SMBIOSBIOSVersion") as string;
if (!string.IsNullOrEmpty(DeviceSMBIOSVersion))
DeviceSMBIOSVersion = DeviceSMBIOSVersion.Trim();
} }
else else
{ {
@@ -59,9 +64,15 @@ namespace Disco.Client.Interop
{ {
if (mItem != null) if (mItem != null)
{ {
DeviceManufacturer = mItem.GetPropertyValue("Manufacturer").ToString().Trim(); DeviceManufacturer = mItem.GetPropertyValue("Manufacturer") as string;
DeviceModel = mItem.GetPropertyValue("Model").ToString().Trim(); if (!string.IsNullOrEmpty(DeviceManufacturer))
DeviceIsPartOfDomain = bool.Parse(mItem.GetPropertyValue("PartOfDomain").ToString()); DeviceManufacturer = DeviceManufacturer.Trim();
DeviceModel = mItem.GetPropertyValue("Model") as string;
if (!string.IsNullOrEmpty(DeviceModel))
DeviceModel = DeviceModel.Trim();
DeviceIsPartOfDomain = (bool)mItem.GetPropertyValue("PartOfDomain");
DeviceType = PCSystemTypeToString((UInt16)mItem.GetPropertyValue("PCSystemType")); DeviceType = PCSystemTypeToString((UInt16)mItem.GetPropertyValue("PCSystemType"));
} }
else else
@@ -89,8 +100,13 @@ namespace Disco.Client.Interop
{ {
if (mItem != null) if (mItem != null)
{ {
ComputerSystemProductSerialNumber = mItem.GetPropertyValue("IdentifyingNumber").ToString().Trim(); ComputerSystemProductSerialNumber = mItem.GetPropertyValue("IdentifyingNumber") as string;
DeviceUUID = mItem.GetPropertyValue("UUID").ToString().Trim(); if (!string.IsNullOrEmpty(ComputerSystemProductSerialNumber))
ComputerSystemProductSerialNumber = ComputerSystemProductSerialNumber.Trim();
DeviceUUID = mItem.GetPropertyValue("UUID") as string;
if (!string.IsNullOrEmpty(DeviceUUID))
DeviceUUID = DeviceUUID.Trim();
} }
else else
{ {
@@ -122,7 +138,9 @@ namespace Disco.Client.Interop
{ {
if (mItem != null) if (mItem != null)
{ {
DeviceSerialNumber = mItem.GetPropertyValue("SerialNumber").ToString().Trim(); DeviceSerialNumber = mItem.GetPropertyValue("SerialNumber") as string;
if (!string.IsNullOrEmpty(DeviceSerialNumber))
DeviceSerialNumber = DeviceSerialNumber.Trim();
} }
else else
{ {