Results 1 to 10 of 10
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Owner Name (VB6)

    Is it possible on populating a listbox, to add the name of the user who added the record.
    With the following code, I would like to add the computer or username to the end of the statement.

    <pre> For Each fil In fld.Files
    ' Check for modified date after day before yesterday
    If Int(fil.DateCreated) > Date - 1 Then
    Me.lstFiles.AddItem fil.Name & " " & fil.DateLastModified & " " & User or Computer Name</pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Owner Name (VB6)

    Code to return the computer name (must go into a standard module; declarations at the top):

    Private Const MAX_COMPUTERNAME_LENGTH As Long = 31

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

    Public Function GetComputerName() As String
    Dim dwLen As Long
    Dim strString As String
    'Create a buffer
    dwLen = MAX_COMPUTERNAME_LENGTH + 1
    strString = String(dwLen, "X")
    'Get the computer name
    GetComputerNameA strString, dwLen
    'Get only the actual data
    strString = Left(strString, dwLen)
    'Return the computer name
    GetComputerName = strString
    End Function

    <img src=/w3timages/blueline.gif width=33% height=2>

    Code to get logged in user name (must go into a standard module; declarations at the top):

    Private Declare Function WNetGetUserA Lib "mpr.dll" _
    (ByVal lpszLocalName As String, ByVal lpszUserName As String, lpcchBuffer As Long) As Long

    Public Function GetNetUser() As String
    Dim lpUserName As String, lpnLength As Long, lResult As Long
    'Create a buffer
    lpUserName = String(256, Chr$(0))
    'Get the network user
    lResult = WNetGetUserA(vbNullString, lpUserName, 256)
    If lResult = 0 Then
    GetNetUser = Left$(lpUserName, InStr(1, lpUserName, Chr$(0)) - 1)
    Else
    GetNetUser = "-unknown-"
    End If
    End Function

    Adapted from APIList.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Owner Name (VB6)

    Thanks for the modules Hans.

    Although on the right track, it's not quite what I was after.

    The modules return the user opening the form as opposed to the user or computer who put the image into the system.

    In Win XP, exploring to the image folder, you can see the owner name which returns as above.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Owner Name (VB6)

    <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29> I don't see an owner name for images in Windows XP.

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Owner Name (VB6)

    <img src=/S/innocent.gif border=0 alt=innocent width=20 height=20>

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Owner Name (VB6)

    Hi Dave,

    Try the GetFileOwner function from http://www.devx.com/vb2themax/Tip/19292. You must copy the function plus the declarations into a module; as always, the declarations must be at the top of the module, after Option Explicit. Use it in your code as

    ... fil.Name & " " & fil.DateLastModified & " " & GetFileOwner(fil.Name)

    Note: this function only works on NTFS partitions, not on FAT32.

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Owner Name (VB6)

    Hans

    What would happen if a FAT32 system was present and I didn't know, errorwise ?

    If it caused a big problem then is it really worth usng it ?

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Owner Name (VB6)

    Dave,

    I don't have a FAT32 system to test on, but I would expect the function to return an empty string. If you have a PC with Windows ME, Windows 98 or Windows 95 available, you should test what happens there (those OS'es don't support NTFS.)

  9. #9
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Owner Name (VB6)

    Hans
    Thanks for the help.
    Most of our machines are Win 98 and yes, an empty string is returned.
    Never mind, it was only an after thought.

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Owner Name (VB6)

    That was to be expected. FAT32 systems simply don't store the extra file information such as Owner.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •