我一直在使用Windows的Win32 Classes,并为Windows基于计算机(显然)组建一个库存程序。C#检索MAC地址,HHD大小,内存,操作系统版本信息
有没有办法通过程序来收集系统信息并将信息转储到文本文件中?
我期待检索硬件信息(MAC地址,硬盘大小。 安装的RAM,操作系统版本等)
在此先感谢
我一直在使用Windows的Win32 Classes,并为Windows基于计算机(显然)组建一个库存程序。C#检索MAC地址,HHD大小,内存,操作系统版本信息
有没有办法通过程序来收集系统信息并将信息转储到文本文件中?
我期待检索硬件信息(MAC地址,硬盘大小。 安装的RAM,操作系统版本等)
在此先感谢
您可以使用系统的系统信息这一点。它是一个命令行工具,它提供关于一切的信息。 http://technet.microsoft.com/en-us/library/bb491007.aspx
转储到文本文件
C:\systeminfo >>C:\a.txt
这应该生成信息的文件。
如果您希望从C#应用程序中调用此命令,则可以使用 System.Diagnostic.Process启动进程以运行相同的命令并生成文件。
它有点像说运行msinfo32它有一切的信息。 OP需要能够从c#中检索信息,您是否可以包含证明这一点的代码? – 2013-02-12 22:43:02
对不起,因为我明白他想要使用某些程序将该信息转储到文本文件,所以我想到了这一点,并使用重定向运算符,这可以转储到文件。我将编辑 – 2013-02-12 23:44:39
MAC中的主题是指MAC地址。我刚刚尝试运行: C:\ systeminfo >> c:\ a.txt 来自终端,它表示systeminfo命令找不到(?) 我想从Macintosh环境中检索信息。我知道Windows的Win32类,并且已经为其中几个编写了一个广泛的程序。我正在查找相当于Macintosh上Win32类的信息。 -J – JMJ 2013-02-13 14:06:00
对于Mac地址,您可以使用System.Net.NetworkInformation.NetworkInterface类找到它。
static string GetMacAddress()
{
string macAddresses = "";
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
// Find all ethernet MACs
if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
macAddresses += nic.GetPhysicalAddress().ToString();
}
}
return macAddresses;
}
要以编程方式查找其他系统规格,您可以使用类似于下面的代码的东西。如果您转到Environment class的MSDN页面,可以找到更多有用的系统信息。
public string SysInfo()
{
Stringbuilder systemInformation = new Stringbuilder(string.Empty);
systemInformation.AppendFormat("Operation System: {0}\n", Environment.OSVersion);
systemInformation.AppendFormat("ProcessorCount: {0}\n", Environment.ProcessorCount);
systemInformation.AppendFormat("SystemDirectory: {0}\n", Environment.SystemDirectory);
systemInformation.AppendFormat("UserDomainName: {0}\n", Environment.UserDomainName);
systemInformation.AppendFormat("UserName: {0}\n", Environment.UserName);
foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
{
// Get each drive
systemInformation.AppendFormat("\t Drive: {0}" +
"\n\t\t VolumeLabel: {1}" +
"\n\t\t DriveType: {2}" +
"\n\t\t DriveFormat: {3}" +
"\n\t\t TotalSize: {4}" +
"\n\t\t AvailableFreeSpace: {5}\n",
DriveInfo1.Name, DriveInfo1.VolumeLabel, DriveInfo1.DriveType,
DriveInfo1.DriveFormat, DriveInfo1.TotalSize, DriveInfo1.AvailableFreeSpace);
}
return systemInformation.ToString();
}
非常感谢您提出这个问题。我正在做一个相同的项目,这是非常有帮助的。
答案正是我所需要的。
我建议的SYSINFO编辑到winglerw28的代码片段()函数:
systemInformation.AppendFormat("\t Drive: {0}" +
"\n\t\t VolumeLabel: {1}" +
"\n\t\t DriveType: {2}" +
"\n\t\t DriveFormat: {3}" +
"\n\t\t TotalSize: {4}" +
"\n\t\t AvailableFreeSpace: {5}\n",
DriveInfo1.Name, DriveInfo1.VolumeLabel, DriveInfo1.DriveType,
DriveInfo1.DriveFormat, DriveInfo1.TotalSize, DriveInfo1.AvailableFreeSpace);
我敢肯定的“DriveInfo1”的引用都应该改为“驱动器”,如下所示:
systemInformation.AppendFormat("\t Drive: {0}" +
"\n\t\t VolumeLabel: {1}" +
"\n\t\t DriveType: {2}" +
"\n\t\t DriveFormat: {3}" +
"\n\t\t TotalSize: {4}" +
"\n\t\t AvailableFreeSpace: {5}\n",
drive.Name, drive.VolumeLabel, drive.DriveType,
drive.DriveFormat, drive.TotalSize, drive.AvailableFreeSpace);
WMI类。请看这个问题,这可能会给你一个良好的开端。 http://stackoverflow.com/questions/9546228/how-to-detect-the-original-mac-address-after-it-has-been-spoofed/9546552#9546552 – Steve 2013-02-12 22:34:32
@JMJ,标题中的“Mac”请参阅MAC地址或Macintosh? – 2013-02-12 22:41:50
@TimLehner我修正了标题。 – 2013-02-12 22:44:40