Acquire Computer Drive

Hi! This is my tutorial entitled "Acquire Computer Drive using VB.Net". Sometimes we have require to get the drives of our computer, but this tutorial gets the list of available drives in ListView. So, now let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add only a ListView named ListView1 to display all the available drives in your computer. You must design your layout like this: design 3. Now, put this code in your Form.
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.         Dim getDrive
  6.         For Each getDrive In Environment.GetLogicalDrives
  7.             Dim InfoDrive As DriveInfo = New DriveInfo(getDrive)
  8.  
  9.             If InfoDrive.DriveType = DriveType.Removable Or InfoDrive.DriveType = DriveType.Fixed Then
  10.                 ListView1.Items.Add(getDrive)
  11.             End If
  12.         Next
  13.     End Sub
  14. End Class

Explanation:

We have imported Imports System.IO to get the IO devices such as the drive. This library contains the DriveInfo method and the DriveType method. We also initialized variable getDrive to be used in the For Each Loop for EnvironmentGetLogicalDrives Method. This method returns an array of string containing the names of the logical drives on the current computer.
  1. If InfoDrive.DriveType = DriveType.Removable Or InfoDrive.DriveType = DriveType.Fixed Then
  2.                 ListView1.Items.Add(getDrive)
  3.             End If
The syntax above indicates that whatever the DriveType is such as a Removable Drive or a Fixed Drive, it will all display in the ListView.

Output:

output Download the source code below and try it! :) For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Add new comment