CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2002
    Location
    Timisoara, Romania
    Posts
    54

    Question Can I get user from windows ?

    Does anyone know ? Can I get the logged in user name from windows/windows NT , or smtg in VB ? directly with code (for use in MS Access forms / VB) ?

  2. #2
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    Code:
    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Private Sub Form_Load()
        Dim strUserName As String
        strUserName = String(100, Chr$(0))
        GetUserName strUserName, 100
        strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
    
        MsgBox "Hello " + strUserName 
    End Sub
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

  3. #3
    Join Date
    Feb 2000
    Posts
    440
    There is an API function (see Platform SDK)

    The function is:

    GetUserName

    Also there is an example provided.

    I am not sure about MS Access but using VB but you shoud have no problems using it from VB.

  4. #4
    Join Date
    Jul 2002
    Posts
    12

    user the function environ

    the fonction environ give lot of thing

    by example:

    for i=0 to 30
    msgbox environ(i)
    next i

    what your asking: environ("username")

    Hope this help.

    Fardoche

  5. #5
    Join Date
    Apr 2005
    Posts
    3

    Cool Re: Can I get user from windows ?

    Let's keep it simple. In this little routine you can return the Username, Operating System, Path and the Computer Name.

    ==========================================================

    Private Sub cmdGetInfo_Click()

    Dim strPath As String
    Dim strUserName As String
    Dim strCompName As String
    Dim strOpSystem As String

    lblPath.WordWrap = True

    strPath = Environ("Path")
    strUserName = Environ("UserName")
    strCompName = Environ("ComputerName")
    strOpSystem = Environ("OS")

    lblPath = strPath
    lblUserName = strUserName & " ---- " & strCompName
    lblOpSystem = strOpSystem
    End Sub

    ==========================================================

    NetWiz

  6. #6
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Can I get user from windows ?

    type SET at a command line, and you will see all the things you can ask environ for..
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured