5 Replies - 1555 Views - Last Post: 29 June 2011 - 06:35 PM Rate Topic: -----

#1 menglim  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-June 11

Shared Folder Monitor in VB.NET

Posted 26 June 2011 - 02:14 AM

I need your help.
Can you give me a function or class which have properties ?
For example:


I shared a folder (C:\shared)

Dim clsObj as new clsSharedMonitor("C:\shared")
'so that I can get its properties like:
clsObj.FullPath() 'Full Path of folder that client are accessing
clsObj.ClientIP() 'IP of computer which access to server
clsObj.UserName() 'UserName of client use to access this sharedfolder
clsObj.DateAccessed() 'date of client access to shared folder
............
...........
..........



Very Urgent !!!!

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Shared Folder Monitor in VB.NET

#2 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Shared Folder Monitor in VB.NET

Posted 26 June 2011 - 05:33 AM

Here's a somewhat basic example, I explain things in the comments:

PointlessObject.vb
Public Class PointlessObject
    'Props exist for the sake of encapsulation, so the data member should be private.
    Private pointlessString As String

    'In C#, you generally call the prop the same thing as the data member with different case, since
    'vb isn't case sensitive though, you need to use something different.
    Public Property PointlessStringProp() As String
        'getter method
        Get
            Return pointlessString
        End Get

        'setter method
        Set(ByVal value As String)
            pointlessString = value
        End Set
    End Property
End Class



Form1.vb
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pointless As New PointlessObject
        pointless.PointlessStringProp = "Hello"
        MessageBox.Show(pointless.PointlessStringProp, "Hi")
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#3 menglim  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-June 11

Re: Shared Folder Monitor in VB.NET

Posted 26 June 2011 - 08:07 AM

I know how to make that kind of class.
but how to make it work as its name.

For example:
method: obj.ClientIP()
It will return IP address of Client which access to sharedfolder.

How to make all those methods and properties work??

View PostTarkenfire, on 26 June 2011 - 05:33 AM, said:

Here's a somewhat basic example, I explain things in the comments:

PointlessObject.vb
Public Class PointlessObject
    'Props exist for the sake of encapsulation, so the data member should be private.
    Private pointlessString As String

    'In C#, you generally call the prop the same thing as the data member with different case, since
    'vb isn't case sensitive though, you need to use something different.
    Public Property PointlessStringProp() As String
        'getter method
        Get
            Return pointlessString
        End Get

        'setter method
        Set(ByVal value As String)
            pointlessString = value
        End Set
    End Property
End Class



Form1.vb
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pointless As New PointlessObject
        pointless.PointlessStringProp = "Hello"
        MessageBox.Show(pointless.PointlessStringProp, "Hi")
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#4 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Shared Folder Monitor in VB.NET

Posted 26 June 2011 - 10:03 AM

Properties simply encapsulate data members so they can be accessed outside of the class if you follow correct OOP principles, so "making them work" is more or less what was shown above.

As for the methods, that's where you'd do any logic to set the data members that the properties expose. You'd have to code those methods to suit whatever setup you may have with this network that you haven't explained at all.

That said, it's quite against the rules here to give code for "free" without some code written already, and I have no intention of breaking that rule.

This post has been edited by Tarkenfire: 26 June 2011 - 10:08 AM

Was This Post Helpful? 0
  • +
  • -

#5 menglim  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-June 11

Re: Shared Folder Monitor in VB.NET

Posted 26 June 2011 - 06:01 PM

I found some code.
It works on VB6 but I wanna convert to VB.NET.

Private Const SESS_GUEST = &H1         'session logged on as a guest
Private Const SESS_NOENCRYPTION = &H2  'session not using encryption
Private Const NERR_SUCCESS As Long = 0&
Private Const MAX_PREFERRED_LENGTH As Long = -1
Private Const ERROR_MORE_DATA As Long = 234&
Private Const LB_SETTABSTOPS As Long = &H192

'for use on Win NT/2000 only
'Windows 95 / 98 is ignored in this case

Private Type SESSION_INFO_502
  sesi502_cname As Long
  sesi502_username As Long
  sesi502_num_open As Long
  sesi502_time As Long
  sesi502_idle_time As Long
  sesi502_user_flags As Long
  sesi502_cltype_name As Long
  sesi502_transport As Long
End Type
 
Private Type FILE_INFO_3
  fi3_id As Long
  fi3_permissions As Long
  fi3_num_locks As Long
  fi3_pathname As Long
  fi3_username As Long
End Type

Private Declare Function NetFileEnum Lib "netapi32" _
  (ByVal ServerName As Long, _
   ByVal basepath As Long, _
   ByVal UserName As Long, _
   ByVal level As Long, _
   bufptr As Long, _
   ByVal prefmaxlen As Long, _
   entriesread As Long, _
   totalentries As Long, _
   resume_handle As Long) As Long
   
Private Declare Function NetFileClose Lib "netapi32" _
    (ByVal ServerName As Long, ByVal FileID As Long) As Long


Private Declare Function NetSessionEnum Lib "netapi32" _
  (ByVal ServerName As Long, _
   ByVal UncClientName As Long, _
   ByVal UserName As Long, _
   ByVal level As Long, _
   bufptr As Long, _
   ByVal prefmaxlen As Long, _
   entriesread As Long, _
   totalentries As Long, _
   resume_handle As Long) As Long
   
Private Declare Function NetApiBufferFree Lib "netapi32" _
   (ByVal Buffer As Long) As Long
   
Private Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long
   
Private Declare Function NetSessionDel Lib "netapi32" _
    (ByRef ServerName As Byte, _
    ByRef UncClientName As Byte, _
    ByRef UserName As Byte) As Long
   

'Private Declare Function NetSessionEnum9x Lib "netapi32" _
'   Alias "NetSessionEnum" _
'  (ByVal pszServer As Long, _
'   ByVal level As Long, _
'   bufptr As Long, _
'cbBuffer As Long, _
'   entriesread As Long, _
'   totalentries As Long) As Long

'common routines
Private Declare Sub CopyMemory Lib "kernel32" _
   Alias "RtlMoveMemory" _
  (pTo As Any, uFrom As Any, _
   ByVal lSize As Long)
   
Private Declare Function lstrlenW Lib "kernel32" _
  (ByVal lpString As Long) As Long
  
  
Private FileIDArray() As Long


Public Sub DeleteOpenFile(lngSelectedList As Long)

Dim dwServer        As Long  'pointer to the server
Dim bServer         As String
Dim success         As Long

    If fncSystemTray.intMonitorSelf = 1 Then
        bServer = fncSystemTray.strOwnComputer
    Else
        bServer = fncSystemTray.strRemoteComputer
    End If
    
    dwServer = StrPtr(bServer)

    success = NetFileClose(dwServer, FileIDArray(lngSelectedList))


End Sub



'call when double item
Public Sub GetOpenFiles(Optional strUserName As String, Optional strFileSearch As String)
    Dim bServer         As String
    Dim bUserName       As String
    Dim dwServer        As Long  'pointer to the server
    Dim success         As Long
    Dim bufptr          As Long  'output
    Dim dwEntriesread   As Long  'out
    Dim dwTotalentries  As Long  'out
    Dim dwResumehandle  As Long  'out
    Dim nStructSize     As Long
    Dim dwUserName As Long
    Dim cnt             As Long
    Dim usrname         As String
    Dim fi3           As FILE_INFO_3
    Dim strFileName As String
    Dim strPermission As String
    Dim lngFileCount As Long
    
   ReDim TabArray(0 To 3) As Long
   
   TabArray(0) = 58
   TabArray(1) = 258
   TabArray(2) = 358
..

.
......







View PostTarkenfire, on 26 June 2011 - 10:03 AM, said:

Properties simply encapsulate data members so they can be accessed outside of the class if you follow correct OOP principles, so "making them work" is more or less what was shown above.

As for the methods, that's where you'd do any logic to set the data members that the properties expose. You'd have to code those methods to suit whatever setup you may have with this network that you haven't explained at all.

That said, it's quite against the rules here to give code for "free" without some code written already, and I have no intention of breaking that rule.

Was This Post Helpful? 0
  • +
  • -

#6 menglim  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-June 11

Re: Shared Folder Monitor in VB.NET

Posted 29 June 2011 - 06:35 PM

Not help :(

View Postmenglim, on 26 June 2011 - 06:01 PM, said:

I found some code.
It works on VB6 but I wanna convert to VB.NET.

Private Const SESS_GUEST = &H1         'session logged on as a guest
Private Const SESS_NOENCRYPTION = &H2  'session not using encryption
Private Const NERR_SUCCESS As Long = 0&
Private Const MAX_PREFERRED_LENGTH As Long = -1
Private Const ERROR_MORE_DATA As Long = 234&
Private Const LB_SETTABSTOPS As Long = &H192

'for use on Win NT/2000 only
'Windows 95 / 98 is ignored in this case

Private Type SESSION_INFO_502
  sesi502_cname As Long
  sesi502_username As Long
  sesi502_num_open As Long
  sesi502_time As Long
  sesi502_idle_time As Long
  sesi502_user_flags As Long
  sesi502_cltype_name As Long
  sesi502_transport As Long
End Type
 
Private Type FILE_INFO_3
  fi3_id As Long
  fi3_permissions As Long
  fi3_num_locks As Long
  fi3_pathname As Long
  fi3_username As Long
End Type

Private Declare Function NetFileEnum Lib "netapi32" _
  (ByVal ServerName As Long, _
   ByVal basepath As Long, _
   ByVal UserName As Long, _
   ByVal level As Long, _
   bufptr As Long, _
   ByVal prefmaxlen As Long, _
   entriesread As Long, _
   totalentries As Long, _
   resume_handle As Long) As Long
   
Private Declare Function NetFileClose Lib "netapi32" _
    (ByVal ServerName As Long, ByVal FileID As Long) As Long


Private Declare Function NetSessionEnum Lib "netapi32" _
  (ByVal ServerName As Long, _
   ByVal UncClientName As Long, _
   ByVal UserName As Long, _
   ByVal level As Long, _
   bufptr As Long, _
   ByVal prefmaxlen As Long, _
   entriesread As Long, _
   totalentries As Long, _
   resume_handle As Long) As Long
   
Private Declare Function NetApiBufferFree Lib "netapi32" _
   (ByVal Buffer As Long) As Long
   
Private Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long
   
Private Declare Function NetSessionDel Lib "netapi32" _
    (ByRef ServerName As Byte, _
    ByRef UncClientName As Byte, _
    ByRef UserName As Byte) As Long
   

'Private Declare Function NetSessionEnum9x Lib "netapi32" _
'   Alias "NetSessionEnum" _
'  (ByVal pszServer As Long, _
'   ByVal level As Long, _
'   bufptr As Long, _
'cbBuffer As Long, _
'   entriesread As Long, _
'   totalentries As Long) As Long

'common routines
Private Declare Sub CopyMemory Lib "kernel32" _
   Alias "RtlMoveMemory" _
  (pTo As Any, uFrom As Any, _
   ByVal lSize As Long)
   
Private Declare Function lstrlenW Lib "kernel32" _
  (ByVal lpString As Long) As Long
  
  
Private FileIDArray() As Long


Public Sub DeleteOpenFile(lngSelectedList As Long)

Dim dwServer        As Long  'pointer to the server
Dim bServer         As String
Dim success         As Long

    If fncSystemTray.intMonitorSelf = 1 Then
        bServer = fncSystemTray.strOwnComputer
    Else
        bServer = fncSystemTray.strRemoteComputer
    End If
    
    dwServer = StrPtr(bServer)

    success = NetFileClose(dwServer, FileIDArray(lngSelectedList))


End Sub



'call when double item
Public Sub GetOpenFiles(Optional strUserName As String, Optional strFileSearch As String)
    Dim bServer         As String
    Dim bUserName       As String
    Dim dwServer        As Long  'pointer to the server
    Dim success         As Long
    Dim bufptr          As Long  'output
    Dim dwEntriesread   As Long  'out
    Dim dwTotalentries  As Long  'out
    Dim dwResumehandle  As Long  'out
    Dim nStructSize     As Long
    Dim dwUserName As Long
    Dim cnt             As Long
    Dim usrname         As String
    Dim fi3           As FILE_INFO_3
    Dim strFileName As String
    Dim strPermission As String
    Dim lngFileCount As Long
    
   ReDim TabArray(0 To 3) As Long
   
   TabArray(0) = 58
   TabArray(1) = 258
   TabArray(2) = 358
..

.
......







View PostTarkenfire, on 26 June 2011 - 10:03 AM, said:

Properties simply encapsulate data members so they can be accessed outside of the class if you follow correct OOP principles, so "making them work" is more or less what was shown above.

As for the methods, that's where you'd do any logic to set the data members that the properties expose. You'd have to code those methods to suit whatever setup you may have with this network that you haven't explained at all.

That said, it's quite against the rules here to give code for "free" without some code written already, and I have no intention of breaking that rule.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1