Get PC Username

Code:

Private Declare PtrSafe Function GetUsername _
Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nsize As Long) _
As LongPtr


Public Function Username() As String
Dim sName As String * 256
Dim cChars As Long
cChars = 256
If GetUsername(sName, cChars) Then
    Username = Left$(sName, cChars - 1)
End If
End Function

Sub ProgramRights()
Dim NameofUser As String
NameofUser = Username
Select Case NameofUser
    Case Is = "Administrator"
        MsgBox "You are the Administrator"
    Case Else
        MsgBox "Your username is " & Username
    End Select


End Sub

Comments are closed.