Computer Science Canada

Windows useraccount

Author:  MIdas0036 [ Fri Jan 11, 2008 4:58 pm ]
Post subject:  Windows useraccount

is there a way i can get VB to call windows useraccounts to get the username and display it in a program (Or Game)

Author:  OneOffDriveByPoster [ Fri Jan 11, 2008 8:13 pm ]
Post subject:  Re: Windows useraccount

Not sure if this is what you are looking for:
http://vbcity.com/page.asp?f=howto&p=system_username

Author:  MIdas0036 [ Sun Jan 13, 2008 11:42 am ]
Post subject:  Re: Windows useraccount

i went to that link did not work for me what i am trying to do is get VB 6 to go into the computer and get the name of the user and display it in a program Very Happy

Author:  OneOffDriveByPoster [ Sun Jan 13, 2008 12:06 pm ]
Post subject:  Re: Windows useraccount

MIdas0036 @ Sun Jan 13, 2008 11:42 am wrote:
i went to that link did not work for me what i am trying to do is get VB 6 to go into the computer and get the name of the user and display it in a program Very Happy
How did it not work? Compile error? Did not get a name back? Crash? Gibberish?

Author:  MIdas0036 [ Wed Jan 16, 2008 12:51 pm ]
Post subject:  Re: Windows useraccount

No Name was returned if you can get the code to work that would help me alot. BooHoo

Author:  OneOffDriveByPoster [ Wed Jan 16, 2008 5:47 pm ]
Post subject:  Re: Windows useraccount

MIdas0036 @ Wed Jan 16, 2008 12:51 pm wrote:
No Name was returned if you can get the code to work that would help me alot. BooHoo
This is what I got...
VisualBASIC:
    Declare Function GetUserNameA Lib "advapi32.dll" Alias _
        "GetUserNameA" (ByVal lpBuffer As String, _
        ByRef nSize As Integer) As Integer

    Public Function GetUserName() As String
        Dim retval As Integer
        Dim username As String
        Dim size As Integer
        username = Space$(255)
        size = 255  'Gets us usernames up to 254 characters long
        retval = GetUserNameA(username, size)
        If retval <> 0 Then
            GetUserName = Left$(username, size - 1)
        Else
            GetUserName = "<unknown>"
        End If
    End Function


: