Get HDD (and NOT Volume) Serial Number on Vista Ultimate 64 bit

后端 未结 7 1280
忘掉有多难
忘掉有多难 2020-12-28 10:05

I was once looking for getting the HDD serial number without using WMI, and I found it. The code I found and posted on StackOverFlow.com works very well on 32 bit Windows, b

7条回答
  •  自闭症患者
    2020-12-28 10:50

    Modified from the code here:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Management;
    using System.Text;
    
    namespace Console_DiskDrive
    {
        class Program
        {
            static void Main(string[] args)
            {
                String query = "SELECT * FROM Win32_DiskDrive";
    
                foreach (ManagementObject item in new ManagementObjectSearcher(query).Get())
                {
                    string serialNumber = Convert.ToString(item["SerialNumber"]);
    
                    Console.WriteLine(serialNumber);
                }
    
                Console.ReadLine();
            }
        }
    }
    

    On my system running Vista Home Premium x64, gives me a 40-character hex string that I'm assuming is my serial number. I'll open up the box and confirm later, but give that a try and see if it's what you're looking for.

提交回复
热议问题