152 lines
4.1 KiB
C#
152 lines
4.1 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Management;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Runtime.InteropServices;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
namespace C4IT_CustomerPanel.libs
|
|
{
|
|
public class InformationHelper
|
|
|
|
{
|
|
private enum QUERY_USER_NOTIFICATION_STATE
|
|
{
|
|
QUNS_NOT_PRESENT = 1,
|
|
QUNS_BUSY = 2,
|
|
QUNS_RUNNING_D3D_FULL_SCREEN = 3,
|
|
QUNS_PRESENTATION_MODE = 4,
|
|
QUNS_ACCEPTS_NOTIFICATIONS = 5,
|
|
QUNS_QUIET_TIME = 6
|
|
};
|
|
|
|
public static DateTime GetLastReboot()
|
|
{
|
|
SelectQuery query =
|
|
|
|
new SelectQuery("SELECT LastBootUpTime FROM Win32_OperatingSystem WHERE Primary = 'true'");
|
|
|
|
|
|
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
|
|
DateTime dtBootTime = DateTime.Now;
|
|
foreach (var o in searcher.Get())
|
|
|
|
{
|
|
var mo = (ManagementObject)o;
|
|
|
|
dtBootTime = ManagementDateTimeConverter.ToDateTime(mo.Properties["LastBootUpTime"].Value.ToString());
|
|
}
|
|
return dtBootTime;
|
|
|
|
}
|
|
|
|
public static decimal getCPUTemp()
|
|
{
|
|
|
|
SelectQuery query =
|
|
|
|
new SelectQuery("SELECT CurrentTemperature FROM Win32_TemperatureProbe");
|
|
|
|
|
|
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
|
|
|
|
|
|
|
|
foreach (var o in searcher.Get())
|
|
{
|
|
|
|
var mo = (ManagementBaseObject)o;
|
|
return (decimal.Parse(mo["CurrentTemperature"].ToString()) / 10 - 273.15m);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static string GetLanguageString(int language)
|
|
{
|
|
string lang;
|
|
switch (language)
|
|
{
|
|
case 1031:
|
|
lang = "de";
|
|
break;
|
|
default:
|
|
lang = "en";
|
|
break;
|
|
}
|
|
return lang;
|
|
}
|
|
|
|
public static string GetIp4Address(bool ShowOnlyInCorporateNetwork)
|
|
{
|
|
var ipInfo = new C4IT.HardwareInfo.cPrimaryIpInfo();
|
|
ipInfo.GetInfo();
|
|
if (!string.IsNullOrEmpty(ipInfo.BestLocalIP) || ShowOnlyInCorporateNetwork)
|
|
return ipInfo.BestLocalIP;
|
|
|
|
|
|
string ip4Address = String.Empty;
|
|
foreach (IPAddress ipa in Dns.GetHostAddresses(Dns.GetHostName()))
|
|
{
|
|
if (ipa.AddressFamily == AddressFamily.InterNetwork)
|
|
{
|
|
ip4Address = ipa.ToString();
|
|
break;
|
|
}
|
|
}
|
|
|
|
return ip4Address;
|
|
}
|
|
|
|
public static DriveInfo[] GetDrives()
|
|
{
|
|
return DriveInfo.GetDrives();
|
|
}
|
|
|
|
public static string FormatBytes(long bytes, bool withSuffix)
|
|
{
|
|
string[] suffix = { "B", "KB", "MB", "GB", "TB" };
|
|
int i;
|
|
double dblSByte = bytes;
|
|
for (i = 0; i < suffix.Length && bytes >= 1024; i++, bytes /= 1024)
|
|
{
|
|
dblSByte = bytes / 1024.0;
|
|
}
|
|
if (withSuffix)
|
|
{
|
|
return String.Format("{0:0.##} {1}", dblSByte, suffix[i]);
|
|
}
|
|
else
|
|
{
|
|
return String.Format("{0:0.##}", dblSByte);
|
|
}
|
|
}
|
|
|
|
[DllImport("shell32.dll")]
|
|
private static extern int SHQueryUserNotificationState(
|
|
out QUERY_USER_NOTIFICATION_STATE pquns);
|
|
|
|
|
|
public static bool IsOsInPresentationMode()
|
|
{
|
|
var hRes = SHQueryUserNotificationState(out var state);
|
|
|
|
if (hRes != 0)
|
|
return false;
|
|
|
|
switch (state)
|
|
{
|
|
case QUERY_USER_NOTIFICATION_STATE.QUNS_ACCEPTS_NOTIFICATIONS:
|
|
case QUERY_USER_NOTIFICATION_STATE.QUNS_QUIET_TIME:
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|