Ok, your using that method so there will be a null character returned and when you append " the great" at the end it gets cut off because of the null.
VB Code:
Option Explicit Private Enum EXTENDED_NAME_FORMAT NameUnknown = 0 NameFullyQualifiedDN = 1 NameSamCompatible = 2 NameDisplay = 3 NameUniqueId = 6 NameCanonical = 7 NameUserPrincipal = 8 NameCanonicalEx = 9 NameServicePrincipal = 10 End Enum Private Declare Function GetUserNameEx Lib "secur32.dll" Alias "GetUserNameExA" _ (ByVal NameFormat As EXTENDED_NAME_FORMAT, ByVal lpNameBuffer As String, ByRef nSize As Long) As Long Private Sub Command1_Click() Dim sBuffer As String, Ret As Long Dim current_user As String sBuffer = String(256, 0) Ret = Len(sBuffer) If GetUserNameEx(NameSamCompatible, sBuffer, Ret) <> 0 Then current_user = Replace(Left$(sBuffer, Ret) & " the great", Chr(0), vbNullString) Else current_user = Replace(Environ("USERNAME") & " the great", Chr(0), vbNullString) End If MsgBox current_user, vbOKOnly End Sub





Reply With Quote