By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

how to get windows (network) login name from vb

samycbe
P: 83
Hi,

How to get the windows login name from vb?

samy
Apr 9 '07 #1
Share this Question
Share on Google+
4 Replies


iburyak
Expert 100+
P: 1,017
I'll get back to you tomorrow if someone will not respond.
Apr 9 '07 #2

iburyak
Expert 100+
P: 1,017
I hope you are familiar with APIs.
If not, just copy this code and use it. If you have some knowledge you can move API declaration to a module.


[PHP]Option Explicit
Private Declare Function WNetGetUser& Lib "Mpr" Alias "WNetGetUserA" (lpname As Any, ByVal lpUserName$, lpnLength&)

Private Sub Form_Load()
Dim username As String
Dim cbusername As Long
Dim ret As Integer


username = Space(256)
cbusername = Len(username)
ret = WNetGetUser(ByVal 0&, username, cbusername)
If ret = 0 Then
' Success - strip off the null.
username = Left(username, InStr(username, Chr(0)) - 1)
Else
username = ""
End If

Debug.Print username
End Sub[/PHP]

Good Luck.
Apr 9 '07 #3

samycbe
P: 83
hai...
its great. Thanks
Apr 10 '07 #4

iburyak
Expert 100+
P: 1,017
Expand|Select|Wrap|Line Numbers
  1. You are welcome.
Apr 10 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.