1

I have been working with the Win32 Classes for Windows and putting together an inventory program for Windows based machines (obviously).

Is there a way to gather the system information through a program and dump the information into a text file?

I am looking to retrieve hardware information (MAC addresses, hard drive size. installed ram, OS version, etc)

Thanks in advance

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
JMJ
  • 35
  • 6

3 Answers3

2

For the Mac address, you can find it using the System.Net.NetworkInformation.NetworkInterface class.

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;
}

To find other system specs programatically, you can use something similar to the code below. If you go to the MSDN page for the Environment class, you can find more useful system information.

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();
}
Elianora
  • 194
  • 1
  • 13
1

Thank you SO much for asking this question. I am doing an identical project and this was VERY helpful.

The answers were exactly what I needed.

I suggest an edit to winglerw28's code snippet for the SysInfo() function:

        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);

I'm pretty sure the "DriveInfo1" references should all be changed to "drive" as follows:

                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);
johncroc
  • 37
  • 1
  • 11
0

You can use SystemInfo for this. its a command line tool which gives information about everything. http://technet.microsoft.com/en-us/library/bb491007.aspx

To dump to text file

C:\systeminfo >>C:\a.txt

This should generate the file with information.

if you want the invoke this command from a C# application you can launch a process using System.Diagnostic.Process to run the same command and the file will be generated.

sumeet kumar
  • 2,628
  • 1
  • 16
  • 24
  • 2
    Its sort of like saying run msinfo32 it has information on everything. The OP needs to be able to retrieve the information from c#, can you include code that demonstrates that? – Jeremy Thompson Feb 12 '13 at 22:43
  • Sorry about that as i Understand he wanted to dump that information to text file using some program so i thought of this and using re directional operators this can be dumped to a file. I'll make an edit – sumeet kumar Feb 12 '13 at 23:44
  • MAC in the subject refers to the MAC address. I just tried running: C:\systeminfo >>c:\a.txt from the terminal and it says that the systeminfo command could not be found (?) I want to retrieve information from the Macintosh environment. I'm aware of the Win32 classes for windows and have already written an extensive program around several of them. I am looking for information that is the equivalent of the Win32 classes on the Macintosh -J – JMJ Feb 13 '13 at 14:06