From 526f8547f79a3c5fdb325fd1aa468986385ae1dc Mon Sep 17 00:00:00 2001 From: Gary Sharp Date: Fri, 24 Mar 2017 15:50:18 +1100 Subject: [PATCH] Client/Bootstrapper Fix: Try gathering model from BaseBoard --- .../Extensions/ClientServicesExtensions.cs | 10 +-- Disco.Client/Interop/Hardware.cs | 75 ++++++++++++------- Disco.ClientBootstrapper/BootstrapperLoop.cs | 10 +-- 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/Disco.Client/Extensions/ClientServicesExtensions.cs b/Disco.Client/Extensions/ClientServicesExtensions.cs index 9ac506ab..3649e3b5 100644 --- a/Disco.Client/Extensions/ClientServicesExtensions.cs +++ b/Disco.Client/Extensions/ClientServicesExtensions.cs @@ -8,13 +8,13 @@ namespace Disco.Client.Extensions { public static class ClientServicesExtensions { -#if DEBUG - public const string ServicePathAuthenticatedTemplate = "http://WS-GSHARP:57252/Services/Client/Authenticated/{0}"; - public const string ServicePathUnauthenticatedTemplate = "http://WS-GSHARP:57252/Services/Client/Unauthenticated/{0}"; -#else +//#if DEBUG +// public const string ServicePathAuthenticatedTemplate = "http://WS-GSHARP:57252/Services/Client/Authenticated/{0}"; +// public const string ServicePathUnauthenticatedTemplate = "http://WS-GSHARP:57252/Services/Client/Unauthenticated/{0}"; +//#else public const string ServicePathAuthenticatedTemplate = "http://DISCO:9292/Services/Client/Authenticated/{0}"; public const string ServicePathUnauthenticatedTemplate = "http://DISCO:9292/Services/Client/Unauthenticated/{0}"; -#endif +//#endif public static ResponseType Post(this ServiceBase Service, bool Authenticated) { diff --git a/Disco.Client/Interop/Hardware.cs b/Disco.Client/Interop/Hardware.cs index 133700a8..595e4fd4 100644 --- a/Disco.Client/Interop/Hardware.cs +++ b/Disco.Client/Interop/Hardware.cs @@ -51,7 +51,7 @@ namespace Disco.Client.Interop { try { - using (var mSearcher = new ManagementObjectSearcher("SELECT SerialNumber, SMBIOSBIOSVersion FROM Win32_BIOS WHERE PrimaryBios=true")) + using (var mSearcher = new ManagementObjectSearcher("SELECT SerialNumber, Manufacturer, SMBIOSBIOSVersion FROM Win32_BIOS WHERE PrimaryBios=true")) { using (var mResults = mSearcher.Get()) { @@ -65,6 +65,12 @@ namespace Disco.Client.Interop DeviceHardware.SerialNumber = serialNumber.Trim(); } + var manufacturer = (string)mItem.GetPropertyValue("Manufacturer"); + if (DeviceHardware.Manufacturer == null && !string.IsNullOrWhiteSpace(manufacturer)) + { + DeviceHardware.Manufacturer = manufacturer.Trim(); + } + ErrorReporting.DeviceIdentifier = DeviceHardware.SerialNumber; } else @@ -85,7 +91,7 @@ namespace Disco.Client.Interop { try { - using (var mSearcher = new ManagementObjectSearcher("SELECT Manufacturer, Model, PartOfDomain, PCSystemType, Domain FROM Win32_ComputerSystem")) + using (var mSearcher = new ManagementObjectSearcher("SELECT Manufacturer, Model, PCSystemType FROM Win32_ComputerSystem")) { using (var mResults = mSearcher.Get()) { @@ -134,7 +140,7 @@ namespace Disco.Client.Interop if (mItem != null) { Enrol.IsPartOfDomain = (bool)mItem.GetPropertyValue("PartOfDomain"); - + if (Enrol.IsPartOfDomain) { Enrol.DNSDomainName = (string)mItem.GetPropertyValue("Domain"); @@ -156,42 +162,59 @@ namespace Disco.Client.Interop private static void ApplyBaseBoardInformation(this DeviceHardware DeviceHardware) { - // Added 2012-11-22 G# - Lenovo IdeaPad Serial SHIM - // http://www.discoict.com.au/forum/feature-requests/2012/11/serial-number-detection-on-ideapads.aspx - if (string.IsNullOrWhiteSpace(DeviceHardware.SerialNumber) || - (DeviceHardware.Manufacturer.Equals("LENOVO", StringComparison.OrdinalIgnoreCase) && - (DeviceHardware.Model.Equals("S10-3", StringComparison.OrdinalIgnoreCase) // S10-3 - || DeviceHardware.Model.Equals("2957", StringComparison.OrdinalIgnoreCase)))) // S10-2 + try { - try + using (var mSearcher = new ManagementObjectSearcher("SELECT SerialNumber, Manufacturer, Model, Product FROM Win32_BaseBoard")) { - using (var mSearcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BaseBoard")) + using (var mResults = mSearcher.Get()) { - using (var mResults = mSearcher.Get()) + using (var mItem = mResults.Cast().FirstOrDefault()) { - using (var mItem = mResults.Cast().FirstOrDefault()) + if (mItem != null) { - if (mItem != null) + // Apply Manufacturer/Model information only if not previously found in Win32_ComputerSystem + var manufacturer = (string)mItem.GetPropertyValue("Manufacturer"); + if (DeviceHardware.Manufacturer == null && !string.IsNullOrWhiteSpace(manufacturer)) { - var serialNumber = (string)mItem.GetPropertyValue("SerialNumber"); - if (!string.IsNullOrWhiteSpace(serialNumber)) - { - DeviceHardware.SerialNumber = serialNumber.Trim(); - ErrorReporting.DeviceIdentifier = DeviceHardware.SerialNumber; - } + DeviceHardware.Manufacturer = manufacturer.Trim(); } - else + + var model = (string)mItem.GetPropertyValue("Model"); + if (DeviceHardware.Model == null && !string.IsNullOrWhiteSpace(model)) { - throw new Exception("No Win32_BaseBoard was found"); + DeviceHardware.Model = model.ToString(); } + + var product = (string)mItem.GetPropertyValue("Product"); + if (DeviceHardware.Model == null && !string.IsNullOrWhiteSpace(product)) + { + DeviceHardware.Model = product.ToString(); + } + + // Added 2012-11-22 G# - Lenovo IdeaPad Serial SHIM + // http://www.discoict.com.au/forum/feature-requests/2012/11/serial-number-detection-on-ideapads.aspx + var serialNumber = (string)mItem.GetPropertyValue("SerialNumber"); + if (!string.IsNullOrWhiteSpace(serialNumber) && + (DeviceHardware.SerialNumber == null || + ((DeviceHardware.Manufacturer?.Equals("LENOVO", StringComparison.OrdinalIgnoreCase) ?? false) && + ((DeviceHardware.Model?.Equals("S10-3", StringComparison.OrdinalIgnoreCase) ?? false) // S10-3 + || (DeviceHardware.Model?.Equals("2957", StringComparison.OrdinalIgnoreCase) ?? false))))) + { + DeviceHardware.SerialNumber = serialNumber.Trim(); + ErrorReporting.DeviceIdentifier = DeviceHardware.SerialNumber; + } + } + else + { + throw new Exception("No Win32_BaseBoard was found"); } } } } - catch (Exception ex) - { - throw new Exception("Disco Client was unable to retrieve BaseBoard information from WMI", ex); - } + } + catch (Exception ex) + { + throw new Exception("Disco Client was unable to retrieve BaseBoard information from WMI", ex); } } diff --git a/Disco.ClientBootstrapper/BootstrapperLoop.cs b/Disco.ClientBootstrapper/BootstrapperLoop.cs index 7e419d8d..09dc0599 100644 --- a/Disco.ClientBootstrapper/BootstrapperLoop.cs +++ b/Disco.ClientBootstrapper/BootstrapperLoop.cs @@ -20,13 +20,13 @@ namespace Disco.ClientBootstrapper private StringBuilder errorMessage; private Process clientProcess; -#if DEBUG - public const string DiscoServerName = "WS-GSHARP"; - public const int DiscoServerPort = 57252; -#else +//#if DEBUG +// public const string DiscoServerName = "WS-GSHARP"; +// public const int DiscoServerPort = 57252; +//#else public const string DiscoServerName = "DISCO"; public const int DiscoServerPort = 9292; -#endif +//#endif public BootstrapperLoop(IStatus StatusUI, LoopCompleteCallback Callback) {