Csharp
get hdd serial by c#
You are missing a reference to the assembly containing the type ManagementObjectSearcher
, which is in the System.Management
namespace. Add this namespace and it should work.
You will have to rightclick the project -> add reference and add the System.Management assembly. System.Managment is not added automatically with the creation of a new project.
code read serial hdd (get serial hdd) by C# language:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
namespace fixLoL32bit
{
class TienIch
{
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();
}
}
}
Read and write registry in C# (csharp)
Read and write registry in C# (csharp)
(Hướng dẫn thao tác với registry trong C#, hướng dẫn làm việc với registry trên C#)