diff --git a/NewLife.Core/Common/MachineInfo.cs b/NewLife.Core/Common/MachineInfo.cs
index 7126ee05a..c3f0a2e13 100644
--- a/NewLife.Core/Common/MachineInfo.cs
+++ b/NewLife.Core/Common/MachineInfo.cs
@@ -37,10 +37,14 @@ public class MachineInfo
[DisplayName("系统版本")]
public String OSVersion { get; set; }
- /// 产品名称。制造商
+ /// 产品名称
[DisplayName("产品名称")]
public String Product { get; set; }
+ /// 制造商
+ [DisplayName("制造商")]
+ public String Vendor { get; set; }
+
/// 处理器型号
[DisplayName("处理器型号")]
public String Processor { get; set; }
@@ -248,26 +252,49 @@ private void LoadWindowsInfo()
if (!str.IsNullOrEmpty()) Guid = str;
reg = Registry.LocalMachine.OpenSubKey(@"SYSTEM\HardwareConfig");
- if (reg != null) str = (reg.GetValue("LastConfig") + "")?.Trim('{', '}').ToUpper();
+ if (reg != null)
+ {
+ str = (reg.GetValue("LastConfig") + "")?.Trim('{', '}').ToUpper();
- // UUID取不到时返回 FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF
- if (!str.IsNullOrEmpty() && !str.EqualIgnoreCase("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF")) UUID = str;
+ // UUID取不到时返回 FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF
+ if (!str.IsNullOrEmpty() && !str.EqualIgnoreCase("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF")) UUID = str;
+ }
reg = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\BIOS");
reg ??= Registry.LocalMachine.OpenSubKey(@"SYSTEM\HardwareConfig\Current");
- if (reg != null) Product = reg.GetValue("SystemProductName") + "";
+ if (reg != null)
+ {
+ Product = (reg.GetValue("SystemProductName") + "").Replace("System Product Name", null);
+ if (Product.IsNullOrEmpty()) Product = reg.GetValue("BaseBoardProduct") + "";
+
+ Vendor = reg.GetValue("SystemManufacturer") + "";
+ if (Vendor.IsNullOrEmpty()) Vendor = reg.GetValue("ASUSTeK COMPUTER INC.") + "";
+ }
reg = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0");
if (reg != null) Processor = reg.GetValue("ProcessorNameString") + "";
+
+ // 旧版系统(如win2008)没有UUID的注册表项,需要用wmic查询。也可能因为过去的某个BUG,导致GUID跟UUID相等
+ if (UUID.IsNullOrEmpty() || UUID == Guid || Vendor.IsNullOrEmpty())
+ {
+ var csproduct = ReadWmic("csproduct", "Name", "UUID", "Vendor");
+ if (csproduct != null)
+ {
+ if (csproduct.TryGetValue("Name", out str) && !str.IsNullOrEmpty() && Product.IsNullOrEmpty()) Product = str;
+ if (csproduct.TryGetValue("UUID", out str) && !str.IsNullOrEmpty()) UUID = str;
+ if (csproduct.TryGetValue("Vendor", out str) && !str.IsNullOrEmpty()) Vendor = str;
+ }
+ }
#else
str = Execute("reg", @"query HKLM\SOFTWARE\Microsoft\Cryptography /v MachineGuid");
if (!str.IsNullOrEmpty() && str.Contains("REG_SZ")) Guid = str.Substring("REG_SZ", null).Trim();
- var csproduct = ReadWmic("csproduct", "Name", "UUID");
+ var csproduct = ReadWmic("csproduct", "Name", "UUID", "Vendor");
if (csproduct != null)
{
if (csproduct.TryGetValue("Name", out str)) Product = str;
if (csproduct.TryGetValue("UUID", out str)) UUID = str;
+ if (csproduct.TryGetValue("Vendor", out str)) Vendor = str;
}
#endif
// 获取内存大小
@@ -386,11 +413,12 @@ private void LoadLinuxInfo()
if (device.TryGetValue("Product", out str))
Product = str;
- else if (dic.TryGetValue("vendor_id", out str))
- Product = str;
else if (dic.TryGetValue("Model", out str))
Product = str;
+ if (dic.TryGetValue("vendor_id", out str))
+ Vendor = str;
+
//if (device.TryGetValue("Fingerprint", out str) && !str.IsNullOrEmpty())
// CpuID = str;
//if (dic.TryGetValue("Serial", out str))
@@ -425,18 +453,21 @@ private void LoadLinuxInfo()
Product = product_name;
// 增加制造商。如 Tencent Cloud,它的产品名只有 CVM。阿里云产品名 Alibaba Cloud ECS
- if (TryRead("/sys/class/dmi/id/sys_vendor", out var vendor) && !vendor.IsNullOrEmpty() && !product_name.Contains(vendor))
+ if (TryRead("/sys/class/dmi/id/sys_vendor", out var vendor) && !vendor.IsNullOrEmpty())
{
- // 红帽KVM太流行,细化处理
- if (product_name == "KVM" && vendor == "Red Hat" &&
- TryRead("/sys/class/dmi/id/product_version", out var ver) && !ver.IsNullOrEmpty())
+ Vendor = vendor;
+
+ if (!product_name.Contains(vendor))
{
- var p = ver.IndexOf('(');
- if (p > 0) ver = ver[..p].Trim();
- Product = ver;
+ // 红帽KVM太流行,细化处理
+ if (product_name == "KVM" && vendor == "Red Hat" &&
+ TryRead("/sys/class/dmi/id/product_version", out var ver) && !ver.IsNullOrEmpty())
+ {
+ var p = ver.IndexOf('(');
+ if (p > 0) ver = ver[..p].Trim();
+ Product = ver;
+ }
}
- else
- Product = $"{vendor} {product_name}";
}
}
@@ -809,11 +840,12 @@ private static String Execute(String cmd, String arguments = null)
///
public static IDictionary ReadWmic(String type, params String[] keys)
{
- var dic = new Dictionary(StringComparer.OrdinalIgnoreCase);
+ var dic = new Dictionary>(StringComparer.OrdinalIgnoreCase);
+ var dic2 = new Dictionary(StringComparer.OrdinalIgnoreCase);
var args = $"{type} get {keys.Join(",")} /format:list";
var str = Execute("wmic", args)?.Trim();
- if (str.IsNullOrEmpty()) return dic;
+ if (str.IsNullOrEmpty()) return dic2;
var ss = str.Split("\r\n");
foreach (var item in ss)
@@ -822,25 +854,21 @@ public static IDictionary ReadWmic(String type, params String[]
if (ks != null && ks.Length >= 2)
{
var k = ks[0].Trim();
- var v = ks[1].Trim();
+ var v = ks[1].Trim().TrimInvisible();
if (!k.IsNullOrEmpty() && !v.IsNullOrEmpty())
{
- if (dic.TryGetValue(k, out var val))
- dic[k] = val + "," + v;
- else
- dic[k] = v;
+ if (!dic.TryGetValue(k, out var list))
+ dic[k] = list = new List();
+
+ list.Add(v);
}
}
}
// 排序,避免多个磁盘序列号时,顺序变动
- var dic2 = new Dictionary(StringComparer.OrdinalIgnoreCase);
foreach (var item in dic)
{
- if (item.Value.Contains(','))
- dic2[item.Key] = item.Value.Split(',').OrderBy(e => e.TrimInvisible()).Join();
- else
- dic2[item.Key] = item.Value.TrimInvisible();
+ dic2[item.Key] = item.Value.OrderBy(e => e).Join();
}
return dic2;
diff --git a/NewLife.Core/Log/Logger.cs b/NewLife.Core/Log/Logger.cs
index 89fe28823..dbf952e4b 100644
--- a/NewLife.Core/Log/Logger.cs
+++ b/NewLife.Core/Log/Logger.cs
@@ -247,7 +247,7 @@ protected static String GetHead()
{
sb.AppendFormat("#Memory: {0:n0}M/{1:n0}M\r\n", mi.AvailableMemory / 1024 / 1024, mi.Memory / 1024 / 1024);
sb.AppendFormat("#Processor: {0}\r\n", mi.Processor);
- if (!mi.Product.IsNullOrEmpty()) sb.AppendFormat("#Product: {0}\r\n", mi.Product);
+ if (!mi.Product.IsNullOrEmpty()) sb.AppendFormat("#Product: {0} / {1}\r\n", mi.Product, mi.Vendor);
if (mi.Temperature > 0) sb.AppendFormat("#Temperature: {0}\r\n", mi.Temperature);
}
sb.AppendFormat("#GC: IsServerGC={0}, LatencyMode={1}\r\n", GCSettings.IsServerGC, GCSettings.LatencyMode);