Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get IP address and user name use FileSystemWatche
Message
From
03/09/2008 00:44:11
 
 
To
02/09/2008 03:31:52
Vijay Kumar
DNS ERP Pvt Ltd
India
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB.NET 1.1
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01336510
Message ID:
01344386
Views:
472
>>But I want to watch all client activity with the server through FileSystemWatcher.<

It sounds like you want to monitor this activity on the server-side. Is this a web server? I'm sure there are utilities out there for monitoring this kind of activity on a web server (you have not figured out how to get the user name and IP of the person changing the files, correct?) I don't know anything about such things though ... maybe some Google searches will help, or maybe someone else here can jump in with some ideas. Sorry. =0(

~~Bonnie




>Hi Bonnie,
>
>I used such codes given below->.............
>
>Imports System.IO
>Imports System.Diagnostics
>Public Class Form1
> Inherits System.Windows.Forms.Form
> Public watchfolder As FileSystemWatcher
> Public ab As String
> Public lpUserName As String
> Public lpnLength, lResult As Integer
> Public strString As String
>
>
> Private Declare Function w32_WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpszSeverName As String, ByVal lpszUserName As String, ByRef lpcchBuffer As Integer) As Integer
>
>>>>>>>>>>>> The above Function used for get the user name>>>>>>>>>>>>>>>>>>>>>
>
> Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer
>
>>>>>>>>>>>> The above Function used for get the Computer name>>>>>>>>>>>>>>>>>>>>>
>
> Private Sub btn_startwatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_startwatch.Click
> watchfolder = New System.IO.FileSystemWatcher
>
> 'this is the path we want to monitor
> watchfolder.Path = txt_watchpath.Text
> watchfolder.IncludeSubdirectories = True
>
> 'Add a list of Filter we want to specify
> 'make sure you use OR for each Filter as we need to
> 'all of those
>
> watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
> watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
> IO.NotifyFilters.FileName
> watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
> IO.NotifyFilters.Attributes
>
>
> ' add the handler to each event
> AddHandler watchfolder.Changed, AddressOf logchange
> AddHandler watchfolder.Created, AddressOf logchange
> AddHandler watchfolder.Deleted, AddressOf logchange
>
> ' add the rename handler as the signature is different
> AddHandler watchfolder.Renamed, AddressOf logrename
> 'AddHandler watchfolder.Changed, AddressOf syname
>
> 'Set this property to true to start watching
> watchfolder.EnableRaisingEvents = True
> btn_startwatch.Enabled = False
> btn_stop.Enabled = True
> End Sub
> 'End of code for btn_start_click
> Private Sub logchange(ByVal source As Object, ByVal e As _
> System.IO.FileSystemEventArgs)
>
> strString = New String(Chr(0), 255)
> 'Get the computer name
> GetComputerName(strString, 255)
> 'remove the unnecessary chr$(0)'s
> strString = Left.ToString(strString)
>
> If e.ChangeType = IO.WatcherChangeTypes.Changed Then
> txt_folderactivity.Text &= "File " & e.FullPath & _
> " has been modified" & " Event Time " & TimeOfDay() & " System " & strString & vbCrLf
>
> End If
> If e.ChangeType = IO.WatcherChangeTypes.Created Then
> txt_folderactivity.Text &= "File " & e.FullPath & _
> " has been created" & " Event Time " & TimeOfDay() & " System " & strString & vbCrLf
>
> End If
> If e.ChangeType = IO.WatcherChangeTypes.Deleted Then
> txt_folderactivity.Text &= "File " & e.FullPath & _
> " has been deleted" & " Event Time " & TimeOfDay() & " System " & strString & vbCrLf
>
> End If
> End Sub
>
> Public Sub logrename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
>
> txt_folderactivity.Text &= "File" & e.OldName & _
> " has been renamed to " & e.Name & " Event Time " & TimeOfDay() & " System " & strString & vbCrLf
> lpUserName = New String(Chr(0), 256)
> lResult = w32_WNetGetUser(vbNullString, lpUserName, 256)
> lpUserName = Left.ToString(lpUserName)
> End Sub
> Private Sub btn_stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_stop.Click
> watchfolder.EnableRaisingEvents = False
> btn_startwatch.Enabled = True
> btn_stop.Enabled = False
> txt_folderactivity.Text = ""
> End Sub
>
> Public Sub syname(ByVal sender As Object, ByVal e As System.IO.ErrorEventArgs)
>
>
> End Sub
>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
> lpUserName = New String(Chr(0), 256)
> lResult = w32_WNetGetUser(VBNullString,lpUserName, 256)
> lpUserName = Left.ToString(lpUserName)
> MessageBox.Show(lpUserName)
>
>
> 'Create a buffer
> strString = New String(Chr(0), 255)
> ' Get the computer name
> GetComputerName(strString, 255)
> 'remove the unnecessary chr$(0)'s
> strString = Left.ToString(strString)
> 'Show the computer name
> MessageBox.Show(strString)
>
>
> End Sub
>End Class
>
>But I want to watch all client activity with the server through FileSystemWatcher.
>
>Regards
>
>Vijay
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform