5 Replies - 2483 Views - Last Post: 07 June 2010 - 11:37 AM

#1 firebolt   User is offline

  • D.I.C Lover
  • member icon

Reputation: 93
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Get windows username

Posted 17 April 2009 - 11:19 PM

Description: Just place in the code view and start form. Username will appear.
Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Sub Form_Activate()
 Dim Result As Long
 Dim Username As String
 Dim LenUserName As Long
 Cls
 LenUserName = 256
 Username = Space(LenUserName)
 Result = GetUserName(Username, LenUserName)
 If Result <> 0 Then
Print Left$(Username, LenUserName)
 Else
  Print "Error"
 End If
End Sub






Is This A Good Question/Topic? 0
  • +

Replies To: Get windows username

#2 paperclipmuffin   User is offline

  • Disassembling...
  • member icon

Reputation: 13
  • View blog
  • Posts: 944
  • Joined: 16-April 09

Re: Get windows username

Posted 06 May 2009 - 11:37 PM


Was This Post Helpful? 0
  • +
  • -

#3 zawhtoo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 21-October 09

Re: Get windows username

Posted 25 October 2009 - 08:18 PM

thanks! so much
Was This Post Helpful? 0
  • +
  • -

#4 javad09359890010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 28-October 09

Re: Get windows username

Posted 27 October 2009 - 11:52 PM

hello my name is javad i am from iran very good i like ahppy time any time for you thank you have a nice day 09359890010
Was This Post Helpful? 0
  • +
  • -

#5 waterbj   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 05-December 09

Re: Get windows username

Posted 05 December 2009 - 12:50 PM

I receive a compile error "Only comments may appear after end sub, end function or end property. THe "Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long" is then highlighted. So where exactly does this go?
Was This Post Helpful? 0
  • +
  • -

#6 msreed   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 14
  • Joined: 22-March 09

Re: Get windows username

Posted 07 June 2010 - 11:37 AM

doesn't this work just as well? dim uname as string = my.user.name
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1