Get Hard Drive Id - CSharp Operating System

CSharp examples for Operating System:Hard Drive

Description

Get Hard Drive Id

Demo Code


using System.Management;
using System;//  w  w w  .  j  av  a 2s .  c om

public class Main{
        public static string GetHardDriveId()
        {
            var drive = "C";
            var dsk = new ManagementObject(
                @"win32_logicaldisk.deviceid=""" + drive + @":""");
            dsk.Get();
            return dsk["VolumeSerialNumber"].ToString();
        }
}

Related Tutorials