Introduction
This sample adds a systemtray icon and logs all the file activities in ur harddisk.
This sample code logs all the changes made to the textfiles.The icon in the system tray has a context menu and it helps in opening the textfile.
'Declarations Dim strpath As String Private ContextMenu1 As ContextMenu Friend WithEvents menuitem1 As MenuItem Friend WithEvents menuitem2 As MenuItem Friend WithEvents NotifyIcon1 As NotifyIcon
'Contents of Initialize component Me.ContextMenu1 = New ContextMenu Me.menuitem1 = New MenuItem Me.menuitem2 = New MenuItem Me.ContextMenu1.MenuItems.Add(Me.menuitem1) Me.ContextMenu1.MenuItems.Add(Me.menuitem2)
Me.menuitem1.Index() = 0 Me.menuitem1.Text = "Open" Me.menuitem2.Index() = 1 Me.menuitem2.Text = "Exit"
Me.NotifyIcon1 = New NotifyIcon(Me.components) NotifyIcon1.Icon = New Icon("face02.ico") NotifyIcon1.ContextMenu = Me.ContextMenu1 NotifyIcon1.Text = "DocViewer by Trishul" NotifyIcon1.Visible = True call Initicon()
Private Sub InitIcon() strpath = Application.StartupPath & "\TLOG.txt" 'File.Create(Application.StartupPath & "\inp.txt") Dim fi As FileInfo = New FileInfo(strpath) If fi.Exists = False Then Dim sc As StreamWriter = New StreamWriter(File.Create(Application.StartupPath & _ "\TLOG.txt")) sc.Close() End If
Dim sw As StreamWriter = New StreamWriter(strpath, True) sw.WriteLine("The Files created on " & DateTime.Now) sw.Close() Dim wc As New FileSystemWatcher wc.Path = "c:\" 'wc.NotifyFilter = NotifyFilters.FileName wc.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or _ NotifyFilters.FileName Or NotifyFilters.DirectoryName Or _ NotifyFilters.CreationTime) wc.Filter = "*.txt" wc.IncludeSubdirectories = True AddHandler wc.Created, AddressOf OnChanged 'AddHandler wc.Changed, AddressOf OnChanged AddHandler wc.Deleted, AddressOf OnChanged AddHandler wc.Renamed, AddressOf OnRenamed wc.EnableRaisingEvents = True
End Sub
Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs) Dim sw As StreamWriter = New StreamWriter(strpath, True) sw.WriteLine("File: " & e.FullPath & " " & e.ChangeType.ToString & _ " at " & DateTime.Now) sw.Close() End Sub
Private Sub OnRenamed(ByVal source As Object, ByVal e As RenamedEventArgs) Dim sw As StreamWriter = New StreamWriter(strpath, True) sw.WriteLine("File: " & e.OldFullPath & "renamed to " & e.FullPath & " at " & _ DateTime.Now) sw.Close() End Sub
Private Sub menuitem1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles menuitem1.Click Process.Start(strpath) Me.Hide() End Sub
Public Shared Sub main() Dim f1 As New Form1 Application.Run() End Sub
|
No responses found. Be the first to respond and make money from revenue sharing program.
|