Results 1 to 9 of 9

Thread: How to get the name of the logged in user

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    How to get the name of the logged in user

    In VB6 we used the GetUserName API call to get the id of the user logged in to the network.

    The application lives on a network drive.

    When I converted the application in VS.net 2003 and ran it I got a security error. Saying something about security permissions do not allow the action to take place.

    When I moved the application to the local C drive the error did not appear.

    The equivalent to GetUserName in .net is System.Security.Principal.WindowsIdentity.GetCurrent.Name. When I added this to a project I started getting different errors.

    How can I have an application on a network drive and read the user id.
    Is this going to be a big issue involving the IT dept.

    Any help would be appreciated.

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Have you tried

    Environment.UserName

    ?
    I don't live here any more.

  3. #3
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    I'm not sure, but I think you may have to do one or both of the following:

    1) Give your application greater security in the GAC.
    2) Give your application greater security using one of the classes (I can't remember which one) in the Security namespace.
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    wossname: I haven't tried that, I will later.

    Sheppe: I don't really know anything of what you said. GAC? Or how to do 2.

    I guess theres lots to learn.

  5. #5

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    Thanks,

    That looks like it will do the trick.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    I am not a member of EE so I could not see the solution.

    Thanks wossname that worked a treat

  8. #8
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Originally posted by davidrobin
    I am not a member of EE so I could not see the solution.

    Thanks wossname that worked a treat
    Next time look at all the page as the answer was right bellow

    VB Code:
    1. User name
    2.  GetUserName = (SystemInformation.UserName.ToString)
    3.  
    4.  
    5. Domain/User
    6.  
    7. Imports System
    8. Imports System.Security
    9.  
    10. Private Function GetUserName() As String
    11.         Return Principal.WindowsIdentity.GetCurrent.Name()
    12.         ' This will return 'domain\username'
    13.     End Function
    \m/\m/

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    Sorry, my mistake

    That is useful to know as well.

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