Tutorials Forums
     Tutorials Videos
        Sign Up Now For FREE
Welcome, Guest
Username Password: Remember me

Use WMI to get total free space on a selected HDD
(1 viewing) (1) Guest
VB.NET HELP, VB.NET TUTORIALS, VB.NET CODE, VB.NET PROGRAMMING, VB.NET

Visual Basic.NET is the most recent generation of Visual Basic. Developers will be pleased to note that its new features include inheritance, method overloading, structured exception handling, and more. These capabilities make it easier than ever to create .NET applications, including Windows applications, web services, and web applications. The articles in this section give you all the tips you need to work wit this useful language.
  • Page:
  • 1

TOPIC: Use WMI to get total free space on a selected HDD

Use WMI to get total free space on a selected HDD 09 Dec 2009 15:27 #70

This snippet uses WMI to get the available free space

Instructions: Need a reference to the following Namespace(s):

System.Management
System.Management.Instrumentation
 
''' <summary>
'
'' method to retrieve the HDD's freespace
'
'' </summary>
''' <param name="drive">Drive letter to get free space from (optional)</param>
'
'' <returns>The free space of the selected HDD</returns>
Public Function GetHDDFreeSpace(ByVal drive As String) As Double
'check to see if the user provided a drive letter
'
if not default it to "C"
If drive = "" OrElse drive Is Nothing Then
drive = "C"
End If
'create our ManagementObject, passing it the drive letter to the
'
DevideID using WQL
Dim disk As New ManagementObject("Win32_LogicalDisk.DeviceID=""" + drive + ":""")
'bind our management object
disk.[Get]()
'
return the free space amount
Return Convert.ToDouble(disk("FreeSpace"))
End Function
 
  • CE
  • OFFLINE
  • Administrator
  • Posts: 197
  • Karma: 77
CodersEngine
  • Page:
  • 1
Time to create page: 0.26 seconds