When working with Windows operating systems, it’s common to encounter error messages that reference specific hard disk volumes, such as \Device\HarddiskVolume3
. These references may seem confusing at first, but they’re actually quite simple to understand and use.
In this article, we’ll explain what these references mean and provide a comprehensive guide on how to tell which drive each hard disk volume refers to in Windows 11 or Windows 10. The step-by-step instructions will enable you to locate the specific device or volume path needed to resolve any file access events issues.
Page Contents
Understanding Hard Disk Volume References
Before we dive into how to find hard disk volume references in Windows, it’s important to understand what they are and why they’re used.
Also see: How to Hide a Drive in Windows 11
In Windows, hard disk volumes are used to organize data on physical hard drives. Each volume is assigned a unique reference, such as:
- \Device\HarddiskVolume3
- \Device\HarddiskVolume4
- \Device\HarddiskVolume5
- \Device\HarddiskVolume1
- \Device\HarddiskVolume2
- \Device\HarddiskVolume6
This reference is used to identify the volume and access its contents.
When troubleshooting issues with Windows, you may encounter error messages that reference a specific hard disk volume. For example, you might see an error message like this:
\Device\HarddiskVolume3\Windows\System32\svchost.exe is missing or corrupted
This error message is telling you that the Windows operating system can’t find the svchost.exe
file on the third hard disk volume. To fix the issue, you’ll need to locate the volume and the file.
Related issue: Service Host Local System (svchost.exe) High CPU, Disk or Memory Usage
How to tell which drive is \Device\HarddiskVolume3 or other volumes?
Now that we understand what hard disk volume references are, let’s take a look at how to find the hard disk volume number and tell which drive each volume is referring to in Windows 11/10.
Method 1: Listing all drive letters and hard disk volume numbers using PowerShell
This method provides you with a comprehensive list of all device names and their corresponding volume paths on your local machine. It leverages PowerShell to query the Windows Management Instrumentation (WMI) class Win32_Volume
for the drive letter and then uses the QueryDosDevice
function from the Kernel32 module to obtain the device path.
To list all the drive letters and their corresponding hard disk volume numbers on your Windows system, follow these steps:
- Open Notepad and paste the following PowerShell script:
$DynAssembly = New-Object System.Reflection.AssemblyName('SysUtils') $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly($DynAssembly, [Reflection.Emit.AssemblyBuilderAccess]::Run) $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule('SysUtils', $False) $TypeBuilder = $ModuleBuilder.DefineType('Kernel32', 'Public, Class') $PInvokeMethod = $TypeBuilder.DefinePInvokeMethod('QueryDosDevice', 'kernel32.dll', ([Reflection.MethodAttributes]::Public -bor [Reflection.MethodAttributes]::Static), [Reflection.CallingConventions]::Standard, [UInt32], [Type[]]@([String], [Text.StringBuilder], [UInt32]), [Runtime.InteropServices.CallingConvention]::Winapi, [Runtime.InteropServices.CharSet]::Auto) $DllImportConstructor = [Runtime.InteropServices.DllImportAttribute].GetConstructor(@([String])) $SetLastError = [Runtime.InteropServices.DllImportAttribute].GetField('SetLastError') $SetLastErrorCustomAttribute = New-Object Reflection.Emit.CustomAttributeBuilder($DllImportConstructor, @('kernel32.dll'), [Reflection.FieldInfo[]]@($SetLastError), @($true)) $PInvokeMethod.SetCustomAttribute($SetLastErrorCustomAttribute) $Kernel32 = $TypeBuilder.CreateType() $Max = 65536 $StringBuilder = New-Object System.Text.StringBuilder($Max) Get-WmiObject Win32_Volume | ? { $_.DriveLetter } | % { $ReturnLength = $Kernel32::QueryDosDevice($_.DriveLetter, $StringBuilder, $Max) if ($ReturnLength) { $DriveMapping = @{ DriveLetter = $_.DriveLetter DevicePath = $StringBuilder.ToString() } New-Object PSObject -Property $DriveMapping } }
- Save the Notepad file with a .ps1 extension, such as List-drives-and-hard-disk-volumes.ps1.
- Run the
List-drives-and-hard-disk-volumes.ps1
script from PowerShell to list all drive letters and their corresponding hard disk volume paths on your Windows 11 or Windows 10 system.
Recommended resource: Run CMD, PowerShell or Regedit as SYSTEM in Windows 11
To run the List-drives-and-hard-disk-volumes.ps1 script from PowerShell, follow these steps:
- Open PowerShell with administrative privileges: Right-click on the Start button or press
Win + X
and then click on “Windows PowerShell (Admin)” or “Windows Terminal (Admin)” if you are using Windows Terminal. Click “Yes” on the User Account Control (UAC) prompt to grant administrative access. - Change the execution policy (if needed): By default, PowerShell may not allow you to run scripts due to its restrictive execution policy. To change the execution policy, type the following command and press Enter:
Set-ExecutionPolicy RemoteSigned
When prompted, type
Y
and press Enter to confirm the change. This command allows you to run scripts that you created or downloaded from the internet, as long as they are signed by a trusted publisher. - Navigate to the script’s location: Use the
cd
command to navigate to the directory where you saved the “List-drives-and-hard-disk-volumes.ps1” script. For example, if you saved the script in the Desktop directory, type the following command and press Enter:cd C:\Users\username\Desktop
Replace the username with your actual user name in your Windows system.
- Run the script: Type the following command and press Enter to run the
List-drives-and-hard-disk-volumes.ps1
script:.\List-drives-and-hard-disk-volumes.ps1
The script will execute and display the device names and their corresponding volume paths for all the drives on your local machine.
- Set the execution policy back to its default value: After running the script, it’s recommended to set the execution policy back to its default value. To do this, type the following command and press Enter:
Set-ExecutionPolicy Restricted
Remember, you need to have administrative privileges to run the script, as it accesses system-level information.
Useful tip: How to Merge Two Drives in Windows 11
Here’s a more detailed explanation of what the script does:
- The script first creates a dynamic assembly called ‘SysUtils’ and defines a P/Invoke method for calling the
QueryDosDevice
function from the Kernel32 module. - It sets the maximum length of the
StringBuilder
object to 65536, which allows it to store the device path information. - The script then uses
Get-WmiObject
to query theWin32_Volume
class for drive letter information. It filters the results to include only objects with a drive letter. - For each drive letter, the script calls the
QueryDosDevice
function with the drive letter as the input. The function returns the length of the device path string, which is then used to create an object containing the drive letter and device path. - Finally, the script outputs the device letter and device path for each drive.
Similar problem: Hard Drive Doesn’t Show Up After Clone in Windows 11
Method 2: Getting the hard disk volume number from a specific drive letter using PowerShell
This method allows you to find the device path for a specific drive letter by using a similar approach as Method 1. However, instead of listing all the device names and their corresponding volume paths, this method prompts you for a single drive letter and returns its device path.
To display the device path for a given device name (drive letter), use the following PowerShell script:
- Open Notepad and paste the following PowerShell script:
$driveLetter = Read-Host "Enter Drive Letter:" Write-Host " " $DynAssembly = New-Object System.Reflection.AssemblyName('SysUtils') $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly($DynAssembly, [Reflection.Emit.AssemblyBuilderAccess]::Run) $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule('SysUtils', $False) $TypeBuilder = $ModuleBuilder.DefineType('Kernel32', 'Public, Class') $PInvokeMethod = $TypeBuilder.DefinePInvokeMethod('QueryDosDevice', 'kernel32.dll', ([Reflection.MethodAttributes]::Public -bor [Reflection.MethodAttributes]::Static), [Reflection.CallingConventions]::Standard, [UInt32], [Type[]]@([String], [Text.StringBuilder], [UInt32]), [Runtime.InteropServices.CallingConvention]::Winapi, [Runtime.InteropServices.CharSet]::Auto) $DllImportConstructor = [Runtime.InteropServices.DllImportAttribute].GetConstructor(@([String])) $SetLastError = [Runtime.InteropServices.DllImportAttribute].GetField('SetLastError') $SetLastErrorCustomAttribute = New-Object Reflection.Emit.CustomAttributeBuilder($DllImportConstructor, @('kernel32.dll'), [Reflection.FieldInfo[]]@($SetLastError), @($true)) $PInvokeMethod.SetCustomAttribute($SetLastErrorCustomAttribute) $Kernel32 = $TypeBuilder.CreateType() $Max = 65536 $StringBuilder = New-Object System.Text.StringBuilder($Max) $ReturnLength = $Kernel32::QueryDosDevice($driveLetter, $StringBuilder, $Max) if ($ReturnLength) { Write-Host "Device Path: "$StringBuilder.ToString() } else { Write-Host "Device Path: not found" } Write-Host " "
- Save the Notepad file with a .ps1 extension, such as Get-device-path-from-drive-letter.ps1.
- Run the
Get-device-path-from-drive-letter.ps1
script from PowerShell. When prompted, enter the drive letter for which you want to retrieve the device path.
To learn how to run the .ps1 PowerShell script you’ve created, follow the instructions as stated in the previous method.
Here’s an overview of what the script does:
- As in Method 1, the script creates a dynamic assembly called ‘SysUtils’ and defines a P/Invoke method for calling the
QueryDosDevice
function from the Kernel32 module. - The script prompts you to enter a drive letter by using the
Read-Host
command. Make sure to enter the drive letter without a trailing backslash (e.g., “C:”, not “C:\”). - It sets the maximum length of the
StringBuilder
object to 65536, allowing it to store the device path information. - The script calls the
QueryDosDevice
function with the input drive letter. If the function is successful, it returns the length of the device path string. - If the
QueryDosDevice
function is successful, the script outputs the device path for the input drive letter. Otherwise, it displays a message indicating that the device path was not found.
Summary
These two methods provide flexible options for obtaining the hard disk volumes information in Windows 11 or 10. Method 1 is useful when you need a comprehensive list of all drive letters and their corresponding volume paths, while Method 2 is more targeted, allowing you to retrieve the hard disk volume path for a specific drive letter. Both methods use PowerShell scripts, making it easy to integrate them into your system management or troubleshooting workflows.