Results 1 to 5 of 5

Thread: Getting logon ID from registry

  1. #1

    Thread Starter
    Lively Member Patrice Bourdages's Avatar
    Join Date
    Jun 2000
    Location
    Quebec, Canada
    Posts
    83

    Question

    I've got a serious problem... I'm trying to find the right way (or tool) to read the registry (WIN95/98, WINNT and WIN2000) at the following location: HKEY_LOCAL_MACHINE\Network\Logon and the variable would be username

    or anything better.

    It's easy to extract from WINNT since we can use the Environ$("OS") and also Environ$("USERNAME") to determine which OS were running and what is the Logged on user... How can I dot it in WIN 95/98???

    Is there anyone out there with the proper answer...

    I need to identify the user from within the application without having them to retype it.

  2. #2
    Lively Member
    Join Date
    Mar 2000
    Posts
    81
    Well, the way I do it is to use "GetUserNameW" in "advapi32.dll". However, we have NT throughout our organisation so see if you can find that library on your win95/98 machines and if so, reply and I'll post all the code.

    Toot
    Some cause happiness wherever they go; others, whenever they go.

  3. #3
    Addicted Member
    Join Date
    Apr 2000
    Location
    Sheffield, England.
    Posts
    136
    Paste this into a module:-

    Code:
    Private Declare Function GetUserName Lib "advapi32.dll" _
                Alias "GetUserNameA" (ByVal lpBuffer As String, _
                nSize As Long) As Long
    
    Public Function UserName() As String
        Dim llReturn As Long
        Dim lsUserName As String
        Dim lsBuffer As String
        
        lsUserName = ""
        lsBuffer = Space$(255)
        llReturn = GetUserName(lsBuffer, 255)
       
        If llReturn Then
           lsUserName = Left$(lsBuffer, InStr(lsBuffer, Chr(0)) - 1)
        End If
        
        UserName = lsUserName
    End Function
    Then you just do stuff like Label1.caption = UserName
    Visual Basic 6 Enterprise Edition + SP4

  4. #4
    Lively Member
    Join Date
    Mar 2000
    Posts
    81

    Wink

    Couldn't have put it better myself!!
    Some cause happiness wherever they go; others, whenever they go.

  5. #5

    Thread Starter
    Lively Member Patrice Bourdages's Avatar
    Join Date
    Jun 2000
    Location
    Quebec, Canada
    Posts
    83

    Talking Thank you

    Thanks a bunch you guys...

    Appreciate it a lot...

    Sincerely yours,

    Patrice Bourdages
    IS Analyst
    Quebec, Quebec, Canada

Posting Permissions

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



Click Here to Expand Forum to Full Width