Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Total Hard Drive Capacity 1

Status
Not open for further replies.

ICTECH

Technical User
Jun 5, 2002
131
0
0
CA
Hi All...

I'm working on a project and I need to pull the total Hard Drive Capacity (Size) in the machine. What I've found so far isn't retrieving the information correctly.. (Ie. 80GB drive is being listed as a 1.18GB) Does anyone have a very reliable way to do this? Thanks...

Her's the code I've tried.
Code:
Private objOS As ManagementObjectSearcher
    Private objCS As ManagementObjectSearcher
    Private objDS As ManagementObjectSearcher
    Private objMgmt As ManagementObject
    Private m_strComputerName As String
    Private m_strManufacturer As String
    Private m_StrModel As String
    Private m_strTPM As String
    Private m_strAssetTag As String
    Private m_strHDCapacity As String

    Public Sub New()

        objOS = New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
        objCS = New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")
        objDS = New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")
        For Each objMgmt In objOS.Get
            m_strComputerName = objMgmt("csname").ToString()
        Next

        For Each objMgmt In objCS.Get
            m_strManufacturer = objMgmt("manufacturer").ToString()
            m_StrModel = objMgmt("model").ToString()
            m_strTPM = objMgmt("totalphysicalmemory").ToString()
        Next

        For Each objMgmt In objDS.Get
            m_strHDCapacity = objMgmt("size").ToString()
        Next
    End Sub

    Public ReadOnly Property HardDriveSize()
        Get
            HardDriveSize = m_strHDCapacity
        End Get
    End Property
 
WMI Query as you have already used is one way for this task.

Also you can use
[tt]
For Each dr As DriveInfo In My.Computer.FileSystem.Drives
dr.Name
dr.TotalSize
dr.DriveType.ToString
dr.TotalFreeSpace
Next[/tt]

etc..

Zameer Abdulla
 
Ah.. I read it again...

You are talking about the total capacity of the hard drive and not the drives.

How many physical hard drives there in the PC? If more than one then try
Code:
        For Each objMgmt In objDS.Get
            m_strHDCapacity = objMgmt("size").ToString()
		Messagebox.show(m_strHDCapacity)
        Next

Are you having any other OS installed in the hard disk?
Why because it won't recognize the partition that has Linux installed.

Zameer Abdulla
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top