Question How to monitor drive activity in vb 2008

Pescadore

Member
Joined
Nov 24, 2009
Messages
13
Programming Experience
5-10
I'm looking for a way to monitor drive activity using Visual Basic 2008. I want to create a small utility to simulate an LED in the system tray for drive read/write activity. I've found several such utilities that do this, but they all lack one thing or another, or they are over bloated with stuff I don't want or need, etc. I want to write my own so it will be like I want it. To get started, I need to know how to monitor drive activity. Can anyone point me in the right direction?
 
Last edited:

Pescadore

Member
Joined
Nov 24, 2009
Messages
13
Programming Experience
5-10
Here's the answer: From bdbodger at MSDN

How to monitor drive activity in vb 2008
Create a form and add 2 PerformanceCounter controls . For the first one set Catagory property to LogicalDisk , CounterName to Disk Read Bytes/sec , InstanceName to _Total for the second PerformanceCounter set CounterName to Disk Write Bytes/sec and the other values the same as the first PerformanceCounter . You will need to create 4 small images that you will use with a notifyIcon and add them to your resources such as these

<some graphics shown here>

Set the form WindowState property to Minimized and the ShowInTaskbar property to false . Add a timer set it's enabled property to true , interval 100 and add a NotifyIcon . Then try this code:

Code:
Public Class Form1

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim both As Integer = 0
        If (PerformanceCounter1.NextValue > 0) Then
            both += 1
        End If

        If (PerformanceCounter2.NextValue > 0) Then
            both += 2
        End If

        Select Case both
            Case 0
                NotifyIcon1.Icon = My.Resources.blue
            Case 1
                NotifyIcon1.Icon = My.Resources.green
            Case 2
                NotifyIcon1.Icon = My.Resources.green2
            Case 3
                NotifyIcon1.Icon = My.Resources.greengreen
        End Select
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        NotifyIcon1.Icon = My.Resources.blue
    End Sub

    Private Sub NotifyIcon1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 

NotifyIcon1.MouseClick
        If e.Button = Windows.Forms.MouseButtons.Right Then
            NotifyIcon1.Visible = False
            Application.Exit()
        End If
    End Sub
End Class
_________________________________________________________________

Change InstanceName to monitor a particular disk drive .
 
Top Bottom