计算机信息查看程序源代码c#
2个回答
展开全部
获取IP
System.Net.IPHostEntry myEntry = System.Net.Dns.GetHostEntry;(System.Net.Dns.GetHostName());
string ipAddress = myEntry.AddressList[0].ToString();
获取内存信息
[StructLayout(LayoutKind.Sequential)]
public struct MEMORY_INFO
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}
[DllImport("kernel32")]
private static extern void GetWindowsDirectory(StringBuilder WinDir, int count);
[DllImport("kernel32")]
private static extern void GetSystemDirectory(StringBuilder SysDir, int count);
[DllImport("kernel32")]
private static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
public static string GetMemInfo()
{
//调用GlobalMemoryStatus函数获取内存的相关信息
MEMORY_INFO MemInfo = new MEMORY_INFO();
GlobalMemoryStatus(ref MemInfo);
StringBuilder sb = new StringBuilder();
//*%的内存正在使用
sb.Append(MemInfo.dwMemoryLoad.ToString() + "% of the memory is being used " + "\r\n");
//总共的物理内存
sb.Append("Physical memory total :" + Utility.ConvertBytes(MemInfo.dwTotalPhys.ToString(), 3) + "GB" + "\r\n");
//可使用的物理内存
sb.Append("Use of physical memory :" + Utility.ConvertBytes(MemInfo.dwAvailPhys.ToString(), 3) + "GB" + "\r\n");
//交换文件总大小
sb.Append("Total size of the swap file" + Utility.ConvertBytes(MemInfo.dwTotalPageFile.ToString(), 3) + "GB" + "\r\n");
//尚可交换文件大小为
sb.Append(" Can still swap file size :" + Utility.ConvertBytes(MemInfo.dwAvailPageFile.ToString(), 3) + "GB" + "\r\n");
//总虚拟内存
sb.Append("The Total virtual memory :" + Utility.ConvertBytes(MemInfo.dwTotalVirtual.ToString(), 3) + "GB" + "\r\n");
//未用虚拟内存有
sb.Append("Unused virtual memory :" + Utility.ConvertBytes(MemInfo.dwAvailVirtual.ToString(), 3) + "GB" + "\r\n");
// ConvertBytes(totMem, 3) + " GB"
return sb.ToString();
}
System.Net.IPHostEntry myEntry = System.Net.Dns.GetHostEntry;(System.Net.Dns.GetHostName());
string ipAddress = myEntry.AddressList[0].ToString();
获取内存信息
[StructLayout(LayoutKind.Sequential)]
public struct MEMORY_INFO
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}
[DllImport("kernel32")]
private static extern void GetWindowsDirectory(StringBuilder WinDir, int count);
[DllImport("kernel32")]
private static extern void GetSystemDirectory(StringBuilder SysDir, int count);
[DllImport("kernel32")]
private static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
public static string GetMemInfo()
{
//调用GlobalMemoryStatus函数获取内存的相关信息
MEMORY_INFO MemInfo = new MEMORY_INFO();
GlobalMemoryStatus(ref MemInfo);
StringBuilder sb = new StringBuilder();
//*%的内存正在使用
sb.Append(MemInfo.dwMemoryLoad.ToString() + "% of the memory is being used " + "\r\n");
//总共的物理内存
sb.Append("Physical memory total :" + Utility.ConvertBytes(MemInfo.dwTotalPhys.ToString(), 3) + "GB" + "\r\n");
//可使用的物理内存
sb.Append("Use of physical memory :" + Utility.ConvertBytes(MemInfo.dwAvailPhys.ToString(), 3) + "GB" + "\r\n");
//交换文件总大小
sb.Append("Total size of the swap file" + Utility.ConvertBytes(MemInfo.dwTotalPageFile.ToString(), 3) + "GB" + "\r\n");
//尚可交换文件大小为
sb.Append(" Can still swap file size :" + Utility.ConvertBytes(MemInfo.dwAvailPageFile.ToString(), 3) + "GB" + "\r\n");
//总虚拟内存
sb.Append("The Total virtual memory :" + Utility.ConvertBytes(MemInfo.dwTotalVirtual.ToString(), 3) + "GB" + "\r\n");
//未用虚拟内存有
sb.Append("Unused virtual memory :" + Utility.ConvertBytes(MemInfo.dwAvailVirtual.ToString(), 3) + "GB" + "\r\n");
// ConvertBytes(totMem, 3) + " GB"
return sb.ToString();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询