user14142511
user14142511

Reputation:

Get drive serial number for a specific drive

I would like to get the drive serial number where the AppData folder is located.

I use this code: SELECT SerialNumber FROM Win32_DiskDrive.

But this returns every serial number (USB, all drive etc.).

How can I only get the drive where the AppData folder is located?

Upvotes: 0

Views: 476

Answers (1)

Rita Han
Rita Han

Reputation: 9710

Assume you are talking about serial number of physical disk drive. One way to achieve this as below you can refer to:

  1. Get drive number from path using PathGetDriveNumber. For example, get C: from AppData path.
  2. Retrieve the logical disk associated with a given physical disk using Win32_DiskDriveToDiskPartition and Win32_LogicalDiskToPartition.

enter image description here

enter image description here

As snapshots above show, you can get C: associated with PHYSICALDRIVE0.

  1. Get serial number of the physical disk using Win32_DiskDrive.

enter image description here

Upvotes: 0

Related Questions