Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 3rd, 2006, 06:03 AM
Registered User
 
Join Date: Sep 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to orfano
Default How to get the Windows user logged in the machine

Lads,

I was wondering how one can code in VB in order to get to know what is the user logged in the Windows. I need to get the user logged so I can go to a databse to get some info regarded to that user.

Thanks in advance,

Flavio

 
Old October 3rd, 2006, 06:59 AM
Registered User
 
Join Date: Sep 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to orfano
Default

Ok Lads,

I confess that I didn't do any reasearch before putting the question here.
I did after and I did find something that did the trick.

I am pasting here as it could be of help for other people.

Cheers,
-----------------------------------------------------------------------------
Private Declare Function GetUserName Lib "advapi32.dll" Alias _
                "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long




Private Sub Command1_Click()

 MsgBox NTDomainUserName()


End Sub

Public Function NTDomainUserName() As String
Dim strBuffer As String * 255
Dim lngBufferLength As Long
Dim lngRet As Long
Dim strTemp As String

    lngBufferLength = 255
    lngRet = GetUserName(strBuffer, lngBufferLength)
    strTemp = UCase(Trim$(strBuffer))
    NTDomainUserName = Left$(strTemp, Len(strTemp) - 1)

End Function






Similar Threads
Thread Thread Starter Forum Replies Last Post
to keep the user logged in until he sign out sarah lee ASP.NET 1.0 and 1.1 Basics 14 December 14th, 2006 11:55 AM
user logged jonyBravo Access 6 November 27th, 2006 09:14 AM
Username of logged in user spardoe BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 August 18th, 2006 01:13 AM
Getting the name of the logged on user Grahame2003 C# 2 March 4th, 2004 04:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.