iT邦幫忙

0

VB 偵測檔案刪除追加刪除者ID

  • 分享至 

  • xImage

我現在的程式可以抓取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
有緣再嘗試 已用另一個麻煩的方式解決

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答