Quantcast
Channel: Número de Série do HD (WPF C#)
Viewing all articles
Browse latest Browse all 2

Número de Série do HD (WPF C#)

$
0
0

Pessoal eu estou querendo pegar o número de série do HD da máquina ao qual está rodando a minha aplicação, eu achei um código no fórum porém não funcionou...

//Namespace Reference
using System.Management

/// <summary>
/// method to retrieve the selected HDD's serial number
/// </summary>
/// <param name="strDriveLetter">Drive letter to retrieve serial number for</param>
/// <returns>the HDD's serial number</returns>
public string GetHDDSerialNumber(string drive)
{
    //check to see if the user provided a drive letter
    //if not default it to "C"
    if (drive == "" || drive == null)
    {
        drive = "C";
    }
    //create our ManagementObject, passing it the drive letter to the
    //DevideID using WQL
    ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive +":\"");
    //bind our management object
    disk.Get();
    //return the serial number
    return disk["VolumeSerialNumber"].ToString();
}

Só que este código não está funcionando o que eu devo fazer?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images