Link to home
Start Free TrialLog in
Avatar of bja1
bja1

asked on

Log user

I want to be able to log the persons that have accessed a vbp, anyone know of code or a site where i could get/do this maybe an ADD-IN?

Thanks in advance
Avatar of adityau
adityau

Please be specific. Whom do you wan to log? The machine name or do you want to ask a login box and log that person's name?
Avatar of bja1

ASKER

network username
Avatar of bja1

ASKER

Ok. I have a project on the network drive that is accessible by all. Now, things are being changed without my consent. Everytime the project is opened I want to write to a text file the nt username or even the machinename of the person and the date/time. This way when people change my work I can figure out who it is.
Sorry for the confusion.
Thanks
Private Sub Form_Load()

    Open "c:\log.txt" For Append As #1
   
        Print #1, "User = " & UserName & _
        " : Machine Name = " & _
        ComputerName & " at " & _
        Format(Now, "short time") & " " _
        & Format(Date, "short date")
   
    Close #1

End Sub

Then in a .bas module

Attribute VB_Name = "Module1"
Private Declare Function SetComputerName Lib "kernel32" Alias "SetComputerNameA" (ByVal lpComputerName As String) As Long


Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function EnableWindow Lib "user32" (ByVal hWnd As Long, ByVal fEnable As Long) As Long

Public Const SW_HIDE = 0
Public Const SW_SHOW = 5

Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type

Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long

Public Function VersioneWindows() As String
    Dim myOS As OSVERSIONINFO

    myOS.dwOSVersionInfoSize = Len(myOS)
    GetVersionEx myOS
    If myOS.dwMajorVersion = 4 Then
        If myOS.dwPlatformId = VER_PLATFORM_WIN32_NT Then
            VersioneWindows = "Windows NT version: "
        ElseIf myOS.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then
            VersioneWindows = "Windows 95 version: "
        End If
    Else
        VersioneWindows = "Windows version: "
    End If
    VersioneWindows = VersioneWindows & myOS.dwMajorVersion & "." & myOS.dwMinorVersion
End Function
Public Sub ApplicationBar(Visible As Boolean)
    Dim hWnd As Long

    hWnd = FindWindow("Shell_TrayWnd", "")
    If Visible Then
        ShowWindow hWnd, SW_SHOW
    Else
        ShowWindow hWnd, SW_HIDE
    End If
    EnableWindow hWnd, Visible
End Sub

Public Sub Desktop(Visible As Boolean)
    Dim hWnd As Long

    hWnd = FindWindow("Progman", "Program Manager")
    If Visible Then
        ShowWindow hWnd, SW_SHOW
    Else
        ShowWindow hWnd, SW_HIDE
    End If
    EnableWindow hWnd, Visible
End Sub
Public Function UserName() As String
    Dim cn As String
    Dim ls As Long
    Dim res As Long

    cn = String(1024, 0)
    ls = 1024
    res = GetUserName(cn, ls)
    If res <> 0 Then
        UserName = Mid(cn, 1, InStr(cn, Chr(0)) - 1)
    Else
        UserName = ""
    End If
End Function


Public Function fSetComputerName(Name As String) As Boolean
    Dim res As Long

    res = SetComputerName(Name)
    SetComputerName = (res <> 0)
End Function
Public Function ComputerName() As String
    Dim cn As String
    Dim ls As Long
    Dim res As Long

    cn = String(1024, 0)
    ls = 1024
    res = GetComputerName(cn, ls)
    If res <> 0 Then
        ComputerName = Mid(cn, 1, InStr(cn, Chr(0)) - 1)
    Else
        ComputerName = ""
    End If
End Function
Avatar of bja1

ASKER

Maybe I'm not very clear with the way I explained the question.  I have a project on a network drive, anyone that has access to this drive (50+) working on a machine with VB installed can open and change the .vbp file.

What i want to know is, is there a way to log the username/machinename and datetime when the vbp is opened, not ran as the person may not run the app just change some code....any ideas
MS Visual SourceSafe...
Avatar of bja1

ASKER

ok you have me as I know sweet FA about VSS i know it keeps the last version of the code but not a log of who has accessed the code.
Avatar of Éric Moreau
With VSS, you can restrict some users to read-only and you can even hide projects to users.
Avatar of bja1

ASKER

Is it hard to set up (believe me the only thing I've touched with VSS is the clicking the no on the "Add to Visaul Source" when opening a new project.
If this is on a network share and the share is on an NTFS partition while not enable 'Auditing' on the share.   Since the share is most likely secured to only allow access to it from certain groups and/or users you could easily setup 'Auditing' to track the following items:

Read
Write
Execute
Delete
Change Permissions
Take Ownership

You will need to have Full Control of the share in order to set this up, but it would be the most effective way to do what you are wanting to do.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial