Link to home
Start Free TrialLog in
Avatar of sgs1970
sgs1970

asked on

Getting windows login name

Hi,
  For getting the windows login user name as a string , what is to be done ?
 I actually used GetEnvironmentVariable, but the value coming when compared to a string variable is not matching

    Thanks,
      Sam
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

what do you mean with "is not matching" ?
can you explain that.
Avatar of sgs1970
sgs1970

ASKER


 Hi,
  See the subroutine I used

 
Function GetUserName() As String
    Dim strUserName As String * 255
    strUserName = ""
    'Create a string buffer of 255 chars in length
    Dim X As Integer
    X = GetEnvironmentVariable("USERNAME", strUserName, Len(strUserName))
    If X > 0 Then        'Look for Null Character, usually included
     X = InStr(strUserName, vbNullChar)
    'Trim off buffered spaces too
        If X > 0 Then
   
         Else
            ''  MsgBox (Left$(strUserName, x))
        End If
    End If

   GetUserName = strUserName
End Function
Avatar of sgs1970

ASKER

The username is not read as a  proper string , it seems
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial