mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 21:21:34 +00:00
109 lines
2.1 KiB
C#
109 lines
2.1 KiB
C#
using System;
|
|
using System.Management;
|
|
|
|
namespace AppleBatch_June
|
|
{
|
|
public class MachineCode
|
|
{
|
|
private string machineCodeString = string.Empty;
|
|
|
|
public string GetMachineCodeString(bool moAddress = false)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(machineCodeString))
|
|
{
|
|
machineCodeString = "PC." + GetCpuInfo() + "." + GetHDid() + ".";
|
|
}
|
|
return machineCodeString + GetMoAddress(moAddress);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return "teluns.";
|
|
}
|
|
}
|
|
|
|
public string GetCpuInfo()
|
|
{
|
|
string text = "";
|
|
try
|
|
{
|
|
using (ManagementClass managementClass = new ManagementClass("Win32_Processor"))
|
|
{
|
|
foreach (ManagementObject instance in managementClass.GetInstances())
|
|
{
|
|
text = instance.Properties["ProcessorId"].Value.ToString();
|
|
instance.Dispose();
|
|
}
|
|
}
|
|
return text.ToString();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public string GetHDid()
|
|
{
|
|
string text = "";
|
|
try
|
|
{
|
|
using (ManagementClass managementClass = new ManagementClass("Win32_DiskDrive"))
|
|
{
|
|
foreach (ManagementObject instance in managementClass.GetInstances())
|
|
{
|
|
text = (string)instance.Properties["Model"].Value;
|
|
instance.Dispose();
|
|
}
|
|
}
|
|
return text.ToString();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public string GetMoAddress(bool dfMacAddress)
|
|
{
|
|
string text = "";
|
|
try
|
|
{
|
|
using (ManagementClass managementClass = new ManagementClass("Win32_NetworkAdapterConfiguration"))
|
|
{
|
|
foreach (ManagementObject instance in managementClass.GetInstances())
|
|
{
|
|
if ((bool)instance["IPEnabled"])
|
|
{
|
|
text = instance["MacAddress"].ToString();
|
|
if (dfMacAddress)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
instance.Dispose();
|
|
}
|
|
}
|
|
return text.ToString();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public string GeSerialNumber()
|
|
{
|
|
try
|
|
{
|
|
return (string)new ManagementObject("win32_logicaldisk.deviceid=\"c:\"").GetPropertyValue("VolumeSerialNumber");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
}
|