C# get computer information
Last modified: July 17, 2021Computer Name
var computerName = System.Environment.MachineName;
Drive Information
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
Console.WriteLine("Drive letter", drive.Name);
Console.WriteLine("Total size {0}", drive.TotalSize);
Console.WriteLine("Total free remaining {0}", drive.AvailableFreeSpace);
Console.WriteLine("Drive format {0}", drive.DriveFormat);
}
OS Name
Need to include using System.Linq; using System.Management;
var os = (from x in new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem").Get().Cast<ManagementObject>()
select x.GetPropertyValue("Caption")).FirstOrDefault();