How can I get internal HDD_DETLAIS = SerialNumber, Model, Manufacturer,TotalHeads ...... etc.
Please help me.. Now my problem is my code run ok, but when I insert external HDD or pen drive then showing the last counting device Details please help ....
i want to show only internal HHD device means OS loaded disk "C" drive
Thanks

Dim HDD_DETLAIS As String
      Dim HDD As New ManagementObjectSearcher("select * from Win32_DiskDrive")

      For Each HDDDET In HDD.Get
          HDD_DETLAIS = HDDDET("SerialNumber") + "   Model-" + HDDDET("Model") + "   Manufacturer-- " + HDDDET("Manufacturer") ' + "  TotalHeads  -  " + hd("TotalHeads") '+ "   Signature - " + hd("Signature")
          TextBox1.Text = HDD_DETLAIS

      Next

Dani AI

Generated

Short version: find which physical disk actually holds the OS volume C: and display only that disk. That avoids guessing "internal" versus "external" (USB devices can present as fixed), and it sidesteps the overwrite/concatenation issue noted by . 's idea of checking for C: is the right direction; use WMI associators to map Win32_LogicalDisk (C:) -> Win32_DiskPartition -> Win32_DiskDrive, then read SerialNumber/Model/Manufacturer from that Win32_DiskDrive object.

Example VB.NET approach (run off the UI thread; trim/validate properties and dispose searchers in production):

Dim parts = New ManagementObjectSearcher("ASSOCIATORS OF {Win32_LogicalDisk.DeviceID='C:'} WHERE AssocClass = Win32_LogicalDiskToPartition")
For Each part As ManagementObject In parts.Get()
  Dim disks = New ManagementObjectSearcher("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & part("DeviceID") & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition")
  For Each disk As ManagementObject In disks.Get()
    Dim serial = If(disk("SerialNumber") IsNot Nothing, disk("SerialNumber").ToString(), "")
    Dim model  = If(disk("Model") IsNot Nothing, disk("Model").ToString(), "")
    Dim manu   = If(disk("Manufacturer") IsNot Nothing, disk("Manufacturer").ToString(), "")
    TextBox1.Text = serial & "   Model-" & model & "   Manufacturer-" & manu
    Exit For
  Next
  If TextBox1.Text <> "" Then Exit For
Next

Notes and gotchas: WMI can be slow—run these calls in a background Task. SerialNumber is not guaranteed to be populated for every drive; if empty, try Win32_PhysicalMedia (Tag matches DiskDrive DeviceID) as a fallback. Some environments (software RAID, virtual disks, dynamic volumes) complicate the mapping—in those cases the logical-to-physical association may not be simple. Finally, WMI queries may require elevated rights on some systems.

Recommended Answers

All 3 Replies

Rather use a select/case block. return the drive names. If there is a C: drive letter from the returned data, show the detail in your textbox.

I now have PCs with SSD (solid state drives.) Maybe this code is destined to fail in a lot of PCs today. May have to test this widely before you publish.

      For Each HDDDET In HDD.Get
          HDD_DETLAIS = etc
          TextBox1.Text = HDD_DETLAIS
      Next

You loop through all the disks setting the text box to dosplay their details BUT each one immediately overwrites the previous one so all you ever see is the last.

To see all the disks you need to concatenate all the details for all the disks (with newlines inbetwen) in the loop, then display that after the loop.
If you want to display just some disks, test the details to see if you want this one before concatenating its details.

commented: The devil is in the DETLAIS. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.