Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Lounger
    Join Date
    Apr 2003
    Location
    Pennsylvania, USA
    Posts
    30
    Thanks
    0
    Thanked 3 Times in 1 Post

    Getting the NT login ID in an Access form

    I would like to use the NT login ID in a parameter I am sending to SQL Server via ODBC Direct to execute a stored procedure. I know I can ask the user to enter it again but if I can use the authenticated user ID from NT, security obviously goes up several notches.

    My goal is be able to check for it when a submit button is cliked on the form which asks for the stored procedure to execute and return a record set to Access.

    I belive I am going to have to call a win api to get this done and which will all be new to me so any and all help as to how this would be done would be greatly appreciated.

  2. #2
    Star Lounger
    Join Date
    May 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the NT login ID in an Access form

    I'm glad you asked this because I have a similar question. I don't need the authentication just the NT User name would do me. Waiting with baited breath for the flood of answers.

  3. #3
    Lounger
    Join Date
    Apr 2003
    Location
    Pennsylvania, USA
    Posts
    30
    Thanks
    0
    Thanked 3 Times in 1 Post

    Re: Getting the NT login ID in an Access form

    I posted in the VB/VBA form and got this answer from Andrew Cronnolly, it seems to work in 98 haven't tried in any NT versions yet, hope it helps.


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

    Function GetUser() As String
    Dim lpBuff As String * 255
    Dim ret As Long, UserName As String
    ret = GetUserName(lpBuff, 255)
    GetUser = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
    End Function

  4. #4
    Star Lounger
    Join Date
    May 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the NT login ID in an Access form

    Magic. Thank you. I will still be interested in seeing the solution for the NT login ID.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    352
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Getting the NT login ID in an Access form

    Generally the login ID is saved as Username in the environment. Try opening the command window (Dos prompt) and typing "set" <enter> (without the quotes). This will give you a list of all the environment variables.

    You then use Environ(Username) in your code to recover the username as a string.

    HTH
    David Grugeon
    Brisbane Australia

  6. #6
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    London, Ontario, Canada
    Posts
    437
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the NT login ID in an Access form

    I use a very similar function with Access '97 Win97-98 and
    Win2000 with complete success. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> You should have no problem on your NT system.

  7. #7
    EPY6323
    Guest

    Re: Getting the NT login ID in an Access form

    Just tried the code on NT 4 and it work just fine.....

  8. #8
    Star Lounger
    Join Date
    May 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the NT login ID in an Access form

    Thanks David. In my experience the login ID is generally not available in the environment parameters except on NT machines. This could be overcome with a login script or batch but I feel it's a bit too easily broken (or hacked).
    I'm grateful for the idea though because I log them away and they come in handy later.

    Very nice to see another Banana Bender in here. I'm also in Brisbane. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  9. #9
    Star Lounger
    Join Date
    May 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the NT login ID in an Access form

    I think there is a bit of confusion here which I may have caused. The original question was how to get hold of and use the NT security key for checking the validity of a user's input. I added to the question by asking how to get hold of the user name. My part of the question has been answered but the original question is still outstanding. The NT security key and the user login are two very different things. The user logs in with his name and password and then the NT Server supplies a security key to the workstation (Correct me if I'm off the beaten track). This is not easily accessed to my knowledge (not that my knowledge is very vast). <img src=/S/2cents.gif border=0 alt=2cents width=15 height=15>

  10. #10
    Star Lounger
    Join Date
    May 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the NT login ID in an Access form

    Just found another problem. Andrew's code works perfectly when the database is on the client machine but as soon as it (the database) is transferred to the server it no longer works because there is no local user and hence no user name.
    Any ideas?

  11. #11
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Getting the NT login ID in an Access form

    Maybe if you explained what you're trying to accomplish you would get more focused answers. It is self-evident that a server doesn't have a username, so what are you trying to accomplish from a server?
    Charlotte

  12. #12
    PatriciaWilliams
    Guest

    Re: Getting the NT login ID in an Access form

    For yourself and for R Adams: I am not sure whether this will be helpful or not, but you know that, when you establish an ODBC connection, that you can include the UserID and Password as embedded, passed parameters. This helps if you know what they are <g>. One method I believe we use in one of our apps is that a call is sent out to grab some information, using a login (membership in a read-only group) and password established for that reason alone -- so that the user, although often a valid user otherwise, does not really interact on his or her personal login. I believe that you have to set something on the NT that will allow the login to the machine to match the login to the SQL Server -- or, that might be the way it is set up by default(?).
    -- That is all I know!
    thx
    Pat

  13. #13
    Star Lounger
    Join Date
    May 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the NT login ID in an Access form

    Strewth, you don't beat around the bush do you. Ok more details - from the thread so far I would like to be able to know which NT user is working on the database. From the code that was supplied I can find the user name and use it in my database. This works fine while the database (front-end) is located on the user's machine (my machine during building of the database). When the database is moved to the server (where I want it to live) I can't use the code supplied to find the user's name. Does this explain the predicament?
    I'm thinking I might have to build a second back-end to reside on the user's machine which will supply the user's name to the front end but I don't like the idea much.

  14. #14
    Lounger
    Join Date
    Apr 2003
    Location
    Pennsylvania, USA
    Posts
    30
    Thanks
    0
    Thanked 3 Times in 1 Post

    Re: Getting the NT login ID in an Access form

    Rob...
    There is always a local user. Usually on a server it is the admin who is logged in on the server at the time. This user probably isn't going to be listed in a user table so it may only appear to be broke..

    Users accessing the MDB file via a share or UNC on the file server are still going to have their own Login ID when they access the MDB file over the network. In that case the posted code will work.

    If the users are accessing the file from a web server then all the user rules change depending on how the web server is set up. If that is the case I will try to explain the best I can in a subsequent post.

    One more thought, it may be that your users don't have enough permissions on the file server. They need to have read, write, and delete because each time they access the MDB file using MS-Access an LDB file gets created. When they close MS-Access if no other users are using the MDB file then the LDB file will get deleted. If they can't delete things can get strange.

    Maybe one of the MVPs can explain what happens better.

  15. #15
    Star Lounger
    Join Date
    May 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the NT login ID in an Access form

    Spot on! When I assigned full control for both the share and the folder security it works (I had assumed that's how it was but I hadn't checked it - the goose alarm has just gone off). The code is executed on the local machine and the user is correctly identified. Thank you and thanks Charlotte for bothering to read my convoluted question.

Page 1 of 2 12 LastLast

Posting Permissions

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