In order to get the volume serial I wrote a function that looks like that:
string drive = Environment.ExpandEnvironmentVariables("%SystemDrive%").Replace(":", "");
string id = getVolumeSerial(drive);
private static string getVolumeSerial(string drive)
{
ManagementObject disk = new ManagementObject(@"win32_logicaldisk.deviceid="""
+ drive + @":""");
disk.Get();
string volumeSerial = disk["VolumeSerialNumber"].ToString();
disk.Dispose();
return volumeSerial;
}
I deployed the software containing that to 30 people but at 31's computer the init of ManagementObject fails and thows an exception. Are there better / alternative / more reliable ways to get the volume serial no?