我現在的程式可以抓取D:\TEST\TEST2\ 底下的檔案什麼時候被刪除的,請問有辦法可以順便抓取是哪個USER刪除的嗎?
' 刪除檔案或目錄時觸發
Private Sub FileSystemWatcher1_Deleted(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Deleted
Dim MyFile As String
MyFile = "C:\FLOG\LOG.TXT"
Dim fPath As String = e.FullPath.Replace("D:\TEST\TEST2", "F:")
If File.Exists(MyFile) = False Then
Dim i As Integer = 1
Dim j As String = "E" & Format(Today, "yyyyMMdd") & Format(Now, "hhmmss") & i
Dim d As String = Format(Today, "yyyy") & "╱" & Format(Today, "MM") & "╱" & Format(Today, "dd")
Dim t As String = Format(Now, "tt hh:mm:ss")
If Left(t, 2) = "AM" Then
t = t.Replace("AM", "上午")
ElseIf Left(t, 2) = "PM" Then
t = t.Replace("PM", "下午")
Else
End If
Dim sw As New StreamWriter(MyFile, True, System.Text.Encoding.GetEncoding("Big5"))
'sw.WriteLine()
sw.WriteLine(j & "," & d & "," & t & "," & "刪除" & "," & fPath & ", ,")
sw.Close()
Else
Dim sr As New StreamReader(MyFile, System.Text.Encoding.GetEncoding("Big5"))
Dim i As Integer = 0
Dim sLine As String = ""
Do
sLine = sr.ReadLine()
i += 1
Loop Until sLine Is Nothing
sr.Close()
Dim j As String = "E" & Format(Today, "yyyyMMdd") & Format(Now, "hhmmss") & i
Dim d As String = Format(Today, "yyyy") & "╱" & Format(Today, "MM") & "╱" & Format(Today, "dd")
Dim t As String = Format(Now, "tt hh:mm:ss")
If Left(t, 2) = "AM" Then
t = t.Replace("AM", "上午")
ElseIf Left(t, 2) = "PM" Then
t = t.Replace("PM", "下午")
Else
End If
Dim sw As New StreamWriter(MyFile, True, System.Text.Encoding.GetEncoding("Big5"))
sw.WriteLine(j & "," & d & "," & t & "," & "刪除" & "," & fPath & ", ,")
sw.Close()
End If
End Sub
後面有找到一些資料 ..
http://vbcity.com/forums/p/133307/698930.aspx#698930
有緣再嘗試 已用另一個麻煩的方式解決