Announcement

Collapse
No announcement yet.

WMI Win32_LogicalDisk and Win32_DiskDrive classes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • WMI Win32_LogicalDisk and Win32_DiskDrive classes

    Does anyone know how to link the WMI Win32_LogicalDisk class info to the the info returned from WMI Win32_DiskDrive class. I need help please!

    What I would like to have is a function to convert \\.\PhysicalDrive1 into C: I'm using Win32_DiskDrive to get drive name, model, etc and wanting to display the drive letter but there does not appear to be drive letter in Win32_DiskDrive class.

    I've found a C# program to do it but it uses GetRelated function which I do not know how to convert to PB. http://vbcity.com/forums/topic.asp?tid=147479

  • #2
    I suggest you look here:

    http://www.jose.it-berater.org/

    Do a search fow WMI. in the forums.

    Good luck.
    Roy Cline

    Comment


    • #3
      Thank you for the info. Jose was the first person I thought of and in fact I'm using his code to do the WMI. However, I don't see a GetRelated function.

      Comment


      • #4
        Here's a vbscript example (I think this is what you want):

        Code:
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        
        Set colDiskDrives = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive")
         
        For Each objDrive In colDiskDrives
            Wscript.Echo "Physical Disk: " & objDrive.Caption & " -- " & objDrive.DeviceID 
            strDeviceID = Replace(objDrive.DeviceID, "\", "\\")
            Set colPartitions = objWMIService.ExecQuery _
                ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
                    strDeviceID & """} WHERE AssocClass = " & _
                        "Win32_DiskDriveToDiskPartition")
         
            For Each objPartition In colPartitions
                Wscript.Echo "Disk Partition: " & objPartition.DeviceID
                Set colLogicalDisks = objWMIService.ExecQuery _
                    ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
                        objPartition.DeviceID & """} WHERE AssocClass = " & _
                            "Win32_LogicalDiskToPartition")
         
                For Each objLogicalDisk In colLogicalDisks
                    Wscript.Echo "Logical Disk: " & objLogicalDisk.DeviceID
                Next
                Wscript.Echo
            Next
            Wscript.Echo
        Next
        I'll leave it up to you to convert to PB...
        --pdf

        Comment


        • #5
          Awesome! Thanks for the code. I'll try to convert to PB and post results!

          Comment


          • #6
            Also...

            James,

            You may also have a look at this

            Choose Win32_LogicalDiskToPartition, Win32_DiskDrive
            and Win32_DiskDriveToDiskPartition in combobox.

            It's based on great José Roca work...
            Last edited by Pierre Bellisle; 6 Sep 2007, 07:39 PM.

            Comment


            • #7
              Perfect! Thanks, you guys rock! Next round is on me!

              Comment

              Working...
              X