Sign in to follow this  
Followers 0
JD2066

Using WMI to get mount point from volume [solved]

4 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm trying to find the mount point a volume has with WMI.

I have the following code to list the volumes and mount points but it doesn't seem to work right.

$WMIService = ObjGet("winmgmts:\\.\root\cimv2")
$WMIMountPoints = $WMIService.ExecQuery("Select * from Win32_MountPoint")
If IsObj($WMIMountPoints) Then
    For $MountPoint in $WMIMountPoints
        MsgBox(0, "WMI Info", $MountPoint.Volume & @CRLF & $MountPoint.Directory)
    Next
EndIf

I would expect the output of $MountPoint.Directory for the C: drive to be C:\ but it's not, the value is Win32_Directory.Name="C:\\".

Anyone know what the problem is?

Justin

Edited by JD2066

Share this post


Link to post
Share on other sites



Don't know how WMI regularly returns path strings, but if you export a registry key

to a .reg file it will also return most path strings this way.

Probably for easy processing by the system, '\' being the C++ escape character ?

Share this post


Link to post
Share on other sites

I just found the solution.

The following code works just fine:

$WMIService = ObjGet("winmgmts:\\.\root\cimv2")
$WMIVolumes = $WMIService.ExecQuery("Select * from Win32_Volume")
If IsObj($WMIVolumes) Then
    For $Volume in $WMIVolumes
        MsgBox(0, "WMI Info", $Volume.Name & @CRLF & $Volume.DeviceID)
    Next
EndIf

I just found using Win32_Volume instead of Win32_MountPoints returns the correct values.

I had assumed before posting that Win32_Volume didn't list MountPoints.

Not sure why I didn't think to check before posting.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0