C# WPF 创建mac地址保存在exe内部
在C# WPF中创建mac地址并保存在exe内部的方法如下:
首先,您需要使用以下代码获取mac地址:
using System.Net.NetworkInformation;
public string GetMacAddress()
{
string macAddress = string.Empty;
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
if (macAddress == string.Empty)
{
IPInterfaceProperties properties = adapter.GetIPProperties();
macAddress = adapter.GetPhysicalAddress().ToString();
}
}
return macAddress;
}
然后,您可以使用以下代码将mac地址保存在exe内部:
using System.IO;
using System.Reflection;
public void SaveMacAddress(string macAddress)
{
string exePath = Assembly.GetEntryAssembly().Location;
string exeDirectory = Path.GetDirectoryName(exePath);
string macAddressFilePath = Path.Combine(exeDirectory, "macAddress.txt");
File.WriteAllText(macAddressFilePath, macAddress);
}
请注意,保存在exe内部的文件可能会被杀毒软件视为潜在的恶意软件行为。您可以使用其他方法来保存mac地址,例如保存在应用程序数据文件夹中或使用注册表等。这样可以避免被杀毒软件误报。
希望能帮到您
原文地址: https://www.cveoy.top/t/topic/hJS4 著作权归作者所有。请勿转载和采集!