M
mipakteh
Guest
Hi All,
What trying to do is,
Want to know when somebody modified or delete files in windows\system32 like a virus do.
Can some one show me how ;
Thank.
Imports System
Imports System.IO
Imports System.Collections
Public Class Form1
Private Data As New List(Of String)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
' files in the folder.
ListFiles(FolderBrowserDialog1.SelectedPath)
End If
End Sub
Private Sub ListFiles(ByVal folderPath As String)
TextBox1.Clear()
Dim fileNames = My.Computer.FileSystem.GetFiles(folderPath, FileIO.SearchOption.SearchTopLevelOnly, "*.*")
For Each fileName As String In fileNames
TextBox1.AppendText(fileName & vbCrLf)
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.SelectedText Is Nothing Then
MessageBox.Show("Please select a file.")
Exit Sub
End If
Dim filePath = TextBox1.SelectedText.ToString
If My.Computer.FileSystem.FileExists(filePath) = False Then
MessageBox.Show("File Not Found: " & filePath)
Exit Sub
End If
Dim fileInfoText As String = GetTextForOutput(filePath)
' fie info
MessageBox.Show(fileInfoText)
End Sub
Private Function GetTextForOutput(ByVal filePath As String) As String
Dim thisFile As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(filePath)
Dim sr As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader(filePath)
If sr.Peek() >= 0 Then
ListBox1.Items.Add("File: " & thisFile.FullName)
ListBox1.Items.Add(vbCrLf)
ListBox1.Items.Add("Modified: " & thisFile.LastWriteTime.ToString)
ListBox1.Items.Add(vbCrLf)
ListBox1.Items.Add("Size: " & thisFile.Length.ToString & " bytes")
ListBox1.Items.Add(vbCrLf)
ListBox1.Items.Add("First Line: " & sr.ReadLine())
End If
sr.Close()
Return sr.ToString
End Function
End Class
Continue reading...
What trying to do is,
Want to know when somebody modified or delete files in windows\system32 like a virus do.
Can some one show me how ;
Thank.
Imports System
Imports System.IO
Imports System.Collections
Public Class Form1
Private Data As New List(Of String)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
' files in the folder.
ListFiles(FolderBrowserDialog1.SelectedPath)
End If
End Sub
Private Sub ListFiles(ByVal folderPath As String)
TextBox1.Clear()
Dim fileNames = My.Computer.FileSystem.GetFiles(folderPath, FileIO.SearchOption.SearchTopLevelOnly, "*.*")
For Each fileName As String In fileNames
TextBox1.AppendText(fileName & vbCrLf)
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.SelectedText Is Nothing Then
MessageBox.Show("Please select a file.")
Exit Sub
End If
Dim filePath = TextBox1.SelectedText.ToString
If My.Computer.FileSystem.FileExists(filePath) = False Then
MessageBox.Show("File Not Found: " & filePath)
Exit Sub
End If
Dim fileInfoText As String = GetTextForOutput(filePath)
' fie info
MessageBox.Show(fileInfoText)
End Sub
Private Function GetTextForOutput(ByVal filePath As String) As String
Dim thisFile As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(filePath)
Dim sr As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader(filePath)
If sr.Peek() >= 0 Then
ListBox1.Items.Add("File: " & thisFile.FullName)
ListBox1.Items.Add(vbCrLf)
ListBox1.Items.Add("Modified: " & thisFile.LastWriteTime.ToString)
ListBox1.Items.Add(vbCrLf)
ListBox1.Items.Add("Size: " & thisFile.Length.ToString & " bytes")
ListBox1.Items.Add(vbCrLf)
ListBox1.Items.Add("First Line: " & sr.ReadLine())
End If
sr.Close()
Return sr.ToString
End Function
End Class
Continue reading...