hard disk capacity in vb.net

  • Thread starter Thread starter Sugavaneswaran
  • Start date Start date
S

Sugavaneswaran

hi all ,

I would like to know the capacity of my harddisk thru VB.NET program.

Can anyone help me in this regard.

thanks
suga
 
You can use WMI to get this information. Here is a code snippet:

---------------------
' This allows use of WMI objects, to get this statement to compile a
reference must be set.
Imports System.Management

' ManagementObjectSearcher retrieves a collection of WMI objects based on '
the query. In this case a string is used instead of a SelectQuery object.

Dim search As New ManagementObjectSearcher("SELECT * FROM
Win32_ComputerSystem")

' Display each entry for Win32_ComputerSystem

Dim info As ManagementObject

For Each info In search.Get()

txtOutput.Text = "Manufacturer: " & info("manufacturer").ToString() & CRLF

txtOutput.Text += "Model: " & info("model").ToString() & CRLF

txtOutput.Text += "System Type: " & info("systemtype").ToString() & CRLF

txtOutput.Text += "Total Physical Memory: " & _

info("totalphysicalmemory").ToString() & CRLF

Next

---------------------

Let me know if you need any further information.

-Prateek


hi all ,

I would like to know the capacity of my harddisk thru VB.NET program.

Can anyone help me in this regard.

thanks
suga
 
WMI is actually a front-end for the PerformanceCounter class and uses
significantly more resources (due to marshalling) than just querying the
PerformanceCounter category yourself. Check MSDN for more info, it's VERY
easy to use... IMO, even easier and less code than WMI.
 
Unfortunately using PerformanceCounter on Win2k (and possibly others) will
cause handle leaks (a known bug in .Net framework) and if it's an Asp.Net
code it will cause application restarts. WMI works fine.

Jerry
 
Back
Top