You must Sign In to post a response.
  • Category: .NET

    How to get computer serial number using windows application c# on windows 10 OS

    Please help me, i have a windows application that is working fine on machines with windows 7 operating system,but when I run/deploy the system on windows 10 machine it does not work.
    This app is suppose to get a serial number of the machine the app is running on,as well as the person logged in on a computer.

    Below is the code that i am using to get computer serial number,it is working well on windows 7,but not on windows 10.

    void GetSerialNumber()
    //Get machine serial number

    SelectQuery Sq = new SelectQuery("Win32_BIOS");
    ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(Sq);
    ManagementObjectCollection osDetailsCollection = objOSDetails.Get();
    foreach (ManagementObject mo in osDetailsCollection)

    string[] BIOSVersion = (string[])mo["BIOSVersion"];
    string s2 = null;
    foreach (string version in BIOSVersion)
    s2 += version;

    lblserialno.Text = mo["SerialNumber"].ToString();

  • #766673

    Have you got any error, while run the same in Windows 10. Please post more details what happen exactly when you run the same in Windows 10.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #766688
    you are selecting the "Win32_BIOS" why can not you try "
    "Win32_OperatingSystem=@". Try the following and

    ManagementObject myManagementObject = new ManagementObject("Win32_OperatingSystem=@");
    string MySN = (string)myManagementObject["SerialNumber"];

    If you want to get is from the registry you can the the following also

    RegistryKey keyBaseX64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
    RegistryKey keyBaseX86 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
    RegistryKey keyX64 = keyBaseX64.OpenSubKey(@"SOFTWARE\Microsoft\Cryptography", RegistryKeyPermissionCheck.ReadSubTree);
    RegistryKey keyX86 = keyBaseX86.OpenSubKey(@"SOFTWARE\Microsoft\Cryptography", RegistryKeyPermissionCheck.ReadSubTree);
    object resultObjX64 = keyX64.GetValue("MachineGuid", (object)"default");
    object resultObjX86 = keyX86.GetValue("MachineGuid", (object)"default");

    By Nathan
    Direction is important than speed

  • #766729
    Hi Nathan,
    Thank you for your response,the code above I think is giving me the serial number of the operating system.i need a serial number of the computer.

    see attachment for the error message I am getting when I use Win32_BIOS / BIOSVersion

    Basically on the foreach loop on the code above, I get a NULLReferenceException error "Object reference not set to an instance of an object"

Sign In to post your comments