What is the easiest way in C# to check if hard disk is SSD without writing any file on hard disk?

WMI will not be able to determine this easily. There is a solution here that's based on the same algorithm Windows 7 uses to determine if a disk is SSD (more on the algorithm here: Windows 7 Enhancements for Solid-State Drives, page 8 and also here: Windows 7 Disk Defragmenter User Interface Overview): Tell whether SSD or not in C#

A quote from the MSDN blog:

Disk Defragmenter looks at the result of directly querying the device through the ATA IDENTIFY DEVICE command. Defragmenter issues IOCTL_ATA_PASS_THROUGH request and checks IDENTIFY_DEVICE_DATA structure. If the NomimalMediaRotationRate is set to 1, this disk is considered a SSD. The latest SSDs will respond to the command by setting word 217 (which is used for reporting the nominal media rotation rate to 1). The word 217 was introduced in 2007 in the ATA8-ACS specification.


This will give you the result on Win10

ManagementScope scope = new ManagementScope(@"\\.\root\microsoft\windows\storage");
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM MSFT_PhysicalDisk");
string type = "";
scope.Connect();
searcher.Scope = scope;

foreach (ManagementObject queryObj in searcher.Get())
{       
    switch (Convert.ToInt16(queryObj["MediaType"]))
    {
        case 1:
            type = "Unspecified";
            break;

        case 3:
            type = "HDD";
            break;

        case 4:
            type = "SSD";
            break;

        case 5:
            type = "SCM";
            break;

        default:
            type = "Unspecified";
            break;
    }
}
searcher.Dispose();

P.s. the string type is the last drive, change to an array to get it for all drives