
-----------------------------------
MIdas0036
Fri Jan 11, 2008 4:58 pm

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)

-----------------------------------
OneOffDriveByPoster
Fri Jan 11, 2008 8:13 pm

Re: Windows useraccount
-----------------------------------
Not sure if this is what you are looking for:
http://vbcity.com/page.asp?f=howto&p=system_username

-----------------------------------
MIdas0036
Sun Jan 13, 2008 11:42 am

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 :D

-----------------------------------
OneOffDriveByPoster
Sun Jan 13, 2008 12:06 pm

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 :DHow did it not work?  Compile error?  Did not get a name back?  Crash?  Gibberish?

-----------------------------------
MIdas0036
Wed Jan 16, 2008 12:51 pm

Re: Windows useraccount
-----------------------------------
No Name was returned if you can get the code to work that would help me alot. :vi:

-----------------------------------
OneOffDriveByPoster
Wed Jan 16, 2008 5:47 pm

Re: Windows useraccount
-----------------------------------
No Name was returned if you can get the code to work that would help me alot. :vi:This is what I got...    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 = ""
        End If
    End Function
