tags:

views:

59

answers:

1

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?

A: 

You could try the method shown in the linked article

helium
do I really in .net have to fall back to winapi?
Kai
I don't know any better alternatives.
helium
is there also a winapi way with c# to get the cpu-id?
Kai