Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to Extract Information of Your Hard Disk using Win32 API in VB.Net (Part 4)

Author: DevASP
Download Source Code : 409_VB.NET - Advanced .NET Framework - Make WIn32 API Calls.zip

This Article has Win32 demonstrations of Hard Disk Information Like Disk Free Space, Disk Free Space Ex, Drive Type etc. This is the Part Four of win32 API Usage.

Whenever we want to Access the windows authentication we have to use Win32 APIs. Because Microsoft gives us his own way to handle events because Microsoft wants no disturbance in its Performance due to your access. 

Each of the Win32 API functions and constants have been wrapped up in the Win32API class for use in each demonstration.

API Calls: This shows how to use the following miscellaneous Win32 API calls: GetDiskFreeSpace, GetDiskFreeSpaceEx, GetDriveType examples for each calling variation. These are examples of calls that returned information that is not obtainable from managed classes.

 

Lets start Understanding by using Code it is recommended that with this explanation please run application First. And try to understand because helpful Comments are written there.

 

First routine shows the free Clusters of your hard disk. Write down the Routine below against the click event of Get disk Free Space Labels Button. This routine gets the number of free clusters on a disk, by Win32 API call GetDiskFreeSpace and updates the function output textbox.

 

Private Sub btnGetFreeSpace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetFreeSpace.Click

Dim rootPathName As String

      Dim sectorsPerCluster As Integer

      Dim bytesPerSector As Integer

      Dim numberOfFreeClusters As Integer

      Dim totalNumberOfClusters As Integer

 

      rootPathName = txtDriveLetter.Text + ":\"

Win32API.GetDiskFreeSpace(rootPathName, sectorsPerCluster,          bytesPerSector, _numberOfFreeClusters, totalNumberOfClusters)

      txtFunctionOutput.Text = "Number of Free Clusters: " & _

     numberOfFreeClusters.ToString()

End Sub

 

Now Second routine deals with free Bytes.

 

Write the Routine below against the click event of Get Disk Free SpaceEx Label’s Button. This gets the number of free bytes on a disk, by Win32 API call GetDiskFreeSpaceEx and updates the function output textbox.

 

Private Sub btnGetDiskFreeSpaceEx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetDiskFreeSpaceEx.Click

   

    Dim rootPathName As String

    Dim freeBytesToCaller As Integer

    Dim totalNumberOfBytes As Integer

    Dim totalNumberOfFreeBytes As UInt32

 

      rootPathName = txtDriveLetter.Text + ":\"

Win32API.GetDiskFreeSpaceEx(rootPathName, freeBytesToCaller, totalNumberOfBytes, totalNumberOfFreeBytes)

      txtFunctionOutput.Text = "Number of Free Bytes: " & _

      totalNumberOfFreeBytes.ToString()

End Sub

 

Write the third Routine below against the click event of  Disk Type Label’s Button.

This shows the drive type by Win32 API call GetDriveTypeand updates the function output textbox.

 

   

Private Sub btnGetDriveType_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetDriveType.Click

 

        Dim rootPathName As String

        rootPathName = txtDriveLetter.Text + ":\"

        Select Case Win32API.GetDriveType(rootPathName)

            Case 2

                txtFunctionOutput.Text = "Drive type: Removable"

            Case 3

                txtFunctionOutput.Text = "Drive type: Fixed"

            Case Is = 4

                txtFunctionOutput.Text = "Drive type: Remote"

            Case Is = 5

                txtFunctionOutput.Text = "Drive type: Cd-Rom"

            Case Is = 6

                txtFunctionOutput.Text = "Drive type: Ram disk"

            Case Else

                txtFunctionOutput.Text = "Drive type: Unrecognized"

        End Select

    End Sub

 

Source code is given with this article .And these Functions Are Given in attached application’s Fourth Tab in Blue Panel. It is recommended run application first.

 

In this Article I tried to Explain the way in which we can get information’s regarding Disks , there are many other Concepts regarding Win32 API in VB.net  I will Explain Others in Later Parts.

Article Comments
Good article
How to use Win32 CreateEvent and OpenEvent in vb.net?

If u have any sample code on this type of event handling. can u please send.
I want to pass events between two applications.

Posted on 5/18/2007 4:40:05 AM by surya

thank u it is very usefull for me.
i required the tooltip has to move when a key has press.if it is not possible please give an idea about any other option.

again thank u!

Posted on 2/12/2009 11:19:02 AM by paul samuel

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to get the Windows Xp Key using VB.Net

Disclaimer - Privacy
© 2002-2017 DevASP.net