605 lines
16 KiB
C#
605 lines
16 KiB
C#
using NLog;
|
|
using System.Management;
|
|
|
|
namespace MP.MONO.Core
|
|
{
|
|
/// <summary>
|
|
/// Gestione info macchina
|
|
/// </summary>
|
|
public class MachineInfo
|
|
{
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Restitusice info richieste
|
|
/// </summary>
|
|
/// <param name="infoType"></param>
|
|
/// <returns></returns>
|
|
public static async Task<Dictionary<string, string>> GetInfo(string infoType)
|
|
{
|
|
var outInfo = new Dictionary<string, string>();
|
|
switch (infoType)
|
|
{
|
|
case "BIOS":
|
|
outInfo = await GetBiosInfo();
|
|
break;
|
|
|
|
case "CPU":
|
|
outInfo = await GetCpuInfo();
|
|
break;
|
|
|
|
case "NET":
|
|
outInfo = await GetNetInfo();
|
|
break;
|
|
|
|
case "OS":
|
|
outInfo = await GetOsInfo();
|
|
break;
|
|
|
|
case "RAM":
|
|
outInfo = await GetRamInfo();
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
return outInfo;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Info BIOS
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private static async Task<Dictionary<string, string>> GetBiosInfo()
|
|
{
|
|
ManagementObjectCollection moc;
|
|
var Processor = new Dictionary<string, string>();
|
|
|
|
try
|
|
{
|
|
moc = new ManagementObjectSearcher("select * from Win32_BIOS").Get();
|
|
}
|
|
catch
|
|
{
|
|
Log.Error("Error: WMI API Not loaded.");
|
|
return Processor;
|
|
}
|
|
|
|
foreach (ManagementObject obj in moc)
|
|
{
|
|
try
|
|
{
|
|
Processor.Add("Manufacturer", obj["Manufacturer"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("ReleaseDate", obj["ReleaseDate"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SMBIOSBIOSVersion", obj["SMBIOSBIOSVersion"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SMBIOSMajorVersion", obj["SMBIOSMajorVersion"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SMBIOSMinorVersion", obj["SMBIOSMinorVersion"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SoftwareElementID", obj["SoftwareElementID"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SoftwareElementState", obj["SoftwareElementState"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SystemBiosMajorVersion", obj["SystemBiosMajorVersion"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SystemBiosMinorVersion", obj["SystemBiosMinorVersion"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Version", obj["Version"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
|
|
return Processor;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Info processore
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private static async Task<Dictionary<string, string>> GetCpuInfo()
|
|
{
|
|
ManagementObjectCollection moc;
|
|
var Processor = new Dictionary<string, string>();
|
|
|
|
try
|
|
{
|
|
moc = new ManagementObjectSearcher("select * from Win32_Processor").Get();
|
|
}
|
|
catch
|
|
{
|
|
Log.Error("Error: WMI API Not loaded.");
|
|
return Processor;
|
|
}
|
|
|
|
foreach (ManagementObject obj in moc)
|
|
{
|
|
try
|
|
{
|
|
Processor.Add("AddressWidth", obj["AddressWidth"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Architecture", obj["Architecture"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("CurrentClockSpeed", obj["CurrentClockSpeed"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("CurrentVoltage", obj["CurrentVoltage"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("DataWidth", obj["DataWidth"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Description", obj["Description"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("ExtClock", obj["ExtClock"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Family", obj["Family"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("L2CacheSize", obj["L2CacheSize"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("L3CacheSize", obj["L3CacheSize"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Level", obj["Level"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("LoadPercentage", obj["LoadPercentage"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Manufacturer", obj["Manufacturer"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("NumberOfCores", obj["NumberOfCores"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("NumberOfLogicalProcessors", obj["NumberOfLogicalProcessors"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("ProcessorId", obj["Processorid"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("ProcessorType", obj["ProcessorType"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Revision", obj["Revision"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Role", obj["Role"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SocketDesignation", obj["SocketDesignation"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SystemName", obj["SystemName"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Version", obj["Version"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
|
|
return Processor;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Info Networking
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private static async Task<Dictionary<string, string>> GetNetInfo()
|
|
{
|
|
ManagementObjectCollection moc;
|
|
var Processor = new Dictionary<string, string>();
|
|
|
|
try
|
|
{
|
|
moc = new ManagementObjectSearcher("select * from Win32_NetworkAdapter WHERE NetEnabled = 'true'").Get();
|
|
}
|
|
catch
|
|
{
|
|
Log.Error("Error: WMI API Not loaded.");
|
|
return Processor;
|
|
}
|
|
|
|
foreach (ManagementObject obj in moc)
|
|
{
|
|
try
|
|
{
|
|
Processor.Add("AdapterType", obj["AdapterType"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Description", obj["Description"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("GUID", obj["GUID"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("MACAddress", obj["MACAddress"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Manufacturer", obj["Manufacturer"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Name", obj["Name"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SystemName", obj["SystemName"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("PhysicalAdapter", obj["PhysicalAdapter"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("ProductName", obj["ProductName"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("ServiceName", obj["ServiceName"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
|
|
return Processor;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Info OS
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private static async Task<Dictionary<string, string>> GetOsInfo()
|
|
{
|
|
ManagementObjectCollection moc;
|
|
var Processor = new Dictionary<string, string>();
|
|
|
|
try
|
|
{
|
|
moc = new ManagementObjectSearcher("select * from Win32_OperatingSystem").Get();
|
|
}
|
|
catch
|
|
{
|
|
Log.Error("Error: WMI API Not loaded.");
|
|
return Processor;
|
|
}
|
|
|
|
foreach (ManagementObject obj in moc)
|
|
{
|
|
try
|
|
{
|
|
Processor.Add("Name", obj["Caption"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Version", obj["Version"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("MaxProcessCount", obj["MaxNumberOfProcesses"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("MaxProcessRAM", obj["MaxProcessMemorySize"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Architecture", obj["OSArchitecture"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SerialNumber", obj["SerialNumber"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Build", obj["BuildNumber"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
|
|
return Processor;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Info RAM
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private static async Task<Dictionary<string, string>> GetRamInfo()
|
|
{
|
|
ManagementObjectCollection moc;
|
|
var Processor = new Dictionary<string, string>();
|
|
|
|
try
|
|
{
|
|
moc = new ManagementObjectSearcher("select * from Win32_PhysicalMemory").Get();
|
|
}
|
|
catch
|
|
{
|
|
Log.Error("Error: WMI API Not loaded.");
|
|
return Processor;
|
|
}
|
|
|
|
foreach (ManagementObject obj in moc)
|
|
{
|
|
try
|
|
{
|
|
Processor.Add("DeviceLocator", obj["DeviceLocator"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("DataWidth", obj["DataWidth"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("ConfiguredVoltage", obj["ConfiguredVoltage"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
try
|
|
{
|
|
Processor.Add("FormFactor", obj["FormFactor"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("ConfiguredClockSpeed", obj["ConfiguredClockSpeed"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SerialNumber", obj["SerialNumber"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("MaxVoltage", obj["MaxVoltage"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("MinVoltage", obj["MinVoltage"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("Speed", obj["Speed"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("SMBIOSMemoryType", obj["SMBIOSMemoryType"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
try
|
|
{
|
|
Processor.Add("PartNumber", obj["PartNumber"].ToString());
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
|
|
return Processor;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |