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

how to get windows (network) login name from vb

P: 83

How to get the windows login name from vb?

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

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

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)
username = ""
End If

Debug.Print username
End Sub[/PHP]

Good Luck.
Apr 9 '07 #3

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

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.