Consulting

Results 1 to 3 of 3

Thread: HELP Please VBA Hard Drive information

  1. #1
    VBAX Newbie
    Joined
    Oct 2019
    Posts
    1
    Location

    HELP Please VBA Hard Drive information

    Hello,

    I hope someone can help me. I've been trying desperately to find a macro which is checking all hard drives and showing me if is a hdd or ssd.

    I used the macro below but it doesn't give me the right information. I also tried different Win32_ Codes but I couldn't make it work or I didn't get the right information. I tried following codes
    WIN32_Physical media - shows me only one row even when it is supposed to show me more information such as mediatype. (https://docs.microsoft.com/en-us/pre...-physicalmedia)
    WIN32_DriveDisk - no infos about hard drive type

    and many more from here = https://docs.microsoft.com/en-us/win...torage-classes

    Thanks in advance.
    Cheers Felix

    Sub LogicalDiskWMI()


    sWQL = "Select * From Win32_LogicalDisk"
    Set oWMISrvEx = GetObject("winmgmts:root/CIMV2")
    Set oWMIObjSet = oWMISrvEx.ExecQuery(sWQL)
    intRow = 2
    strRow = Str(intRow)


    ThisWorkbook.Sheets("LogicalDisk").Range("A1").Value = "Name"
    ThisWorkbook.Sheets("LogicalDisk").Cells(1, 1).Font.Bold = True


    ThisWorkbook.Sheets("LogicalDisk").Range("B1").Value = "Value"
    ThisWorkbook.Sheets("LogicalDisk").Cells(1, 2).Font.Bold = True


    For Each oWMIObjEx In oWMIObjSet


    For Each oWMIProp In oWMIObjEx.Properties_
    If Not IsNull(oWMIProp.Value) Then
    If IsArray(oWMIProp.Value) Then
    For n = LBound(oWMIProp.Value) To UBound(oWMIProp.Value)
    Debug.Print oWMIProp.Name & "(" & n & ")", oWMIProp.Value(n)
    ThisWorkbook.Sheets("LogicalDisk").Range("A" & Trim(strRow)).Value = oWMIProp.Name
    ThisWorkbook.Sheets("LogicalDisk").Range("B" & Trim(strRow)).Value = oWMIProp.Value(n)
    ThisWorkbook.Sheets("LogicalDisk").Range("B" & Trim(strRow)).HorizontalAlignment = xlLeft
    intRow = intRow + 1
    strRow = Str(intRow)
    Next
    Else
    ThisWorkbook.Sheets("LogicalDisk").Range("A" & Trim(strRow)).Value = oWMIProp.Name
    ThisWorkbook.Sheets("LogicalDisk").Range("B" & Trim(strRow)).Value = oWMIProp.Value
    ThisWorkbook.Sheets("LogicalDisk").Range("B" & Trim(strRow)).HorizontalAlignment = xlLeft
    intRow = intRow + 1
    strRow = Str(intRow)
    End If
    End If
    Next
    'End If
    Next
    End Sub

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    does it have to be a vba solution?

    how about HWiNFO...
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    have a look to FSO (FileSystemObject)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •