Win32_DiskDrive > Disk Size in GB instead of bytes

~OSD~ 2,131 Reputation points


I am working with a VB Forms application and collecting disk information. The disk size is retrieved in bytes but I want to get/convert into GB, IF POSSIBLE:

Dim DiskInfo As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_DiskDrive")
For Each queryDisk As ManagementObject In DiskInfo.Get()
RichTextBox1.AppendText("  Size (Bytes): " & queryDisk("Size") & "      " & vbCrLf)
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,706 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,608 questions
0 comments No comments
{count} votes

Accepted answer
  1. TP 79,066 Reputation points


    Divide the number by bytes by 1073741824 and that will give you Gigabytes.

    If the above answers your question, please click Accept Answer.



1 additional answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 27,241 Reputation points Microsoft Vendor

    Hi @~OSD~,

    Don't know if queryDisk("Size") gets a plain numeric string, if so, you can try the following code, if not, you may have to extract its numeric part first.

    RichTextBox1.AppendText("  Size (Gigabytes): " & queryDisk("Size") / 1073741824 & "      " & vbCrLf)

    Best Regards.

    Jiachen Li

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.