Acquire Computer Drive
Submitted by donbermoy on Monday, February 24, 2014 - 07:37.
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:
3. Now, put this code in your Form.
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.
- Imports System.IO
- Public Class Form1
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Dim getDrive
- For Each getDrive In Environment.GetLogicalDrives
- Dim InfoDrive As DriveInfo = New DriveInfo(getDrive)
- If InfoDrive.DriveType = DriveType.Removable Or InfoDrive.DriveType = DriveType.Fixed Then
- ListView1.Items.Add(getDrive)
- End If
- Next
- End Sub
- End Class
Explanation:
We have importedImports 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.
- If InfoDrive.DriveType = DriveType.Removable Or InfoDrive.DriveType = DriveType.Fixed Then
- ListView1.Items.Add(getDrive)
- End If
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
- 21 views