MDFS::Comp.Windows.Hints.FindUser Search  

How to Obtain the name of the current user logged on

Visual Basic:

    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


BBC BASIC:

        DIM alen% 3,name% 256
        !alen%=255:SYS "GetUserName",name%,alen% TO r%
        name%?r%=0:user$=$$name%
        REM user$="" if no user logged on