?
Solved

"LOGON_USER" Server Variable in VBA

Posted on 2003-03-06
9
Medium Priority
?
424 Views
Last Modified: 2012-06-27
I developed a passive logon process in an ASP application on our Intranet.  I use "<%=(Request.ServerVariables("LOGON_USER"))%>" to request the identity of the user.  

The visitor is redirected to a logon failed screen if the userid isn't loaded in the database (every page will do this).

I'd like to set up a similiar process in an Access 2000 application.  Is there equivalent VBA code to this ASP code?

(_|_)
0
Comment
Question by:usafbuttcrack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 

Expert Comment

by:Hume
ID: 8084450
Basically you need the windows user logon name
The following code should suffice


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

Private Function CurrentUserName() As String
    Dim lSize As Long, count As Integer
    Dim sBuffer As String
    sBuffer = String(50, Chr(0))
    lSize = Len(sBuffer)
   
    Do
        Call GetUserName(sBuffer, lSize)
        CurrentUserName = sBuffer
        count = count + 1
    Loop Until Left(CurrentUserName, 1) <> Chr(0) Or count >= 3
End Function

Specialist Application Programmer
IS Developments
0
 
LVL 1

Author Comment

by:usafbuttcrack
ID: 8084484
Hume,

Wow! That was fast! I didn't expect such a quick response.

I won't be able to try this out until tomorrow.  My VBA skills are rudimemtary so I might have to ask for more help.

I'll let you know.

(_|_)
0
 
LVL 1

Author Comment

by:usafbuttcrack
ID: 8084818
Hume,

Wow! That was fast! I didn't expect such a quick response.

I won't be able to try this out until tomorrow.  My VBA skills are rudimemtary so I might have to ask for more help.

I'll let you know.

(_|_)
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 800 total points
ID: 8084889
Alternatively:
environ("username")

will return the current Windows user name. eg:
MsgBox environ("username")
0
 

Expert Comment

by:Hume
ID: 8087145
Think you'll find the environ("username") method only works correctly on NT based machines. Using the API will work on Win9x as well.
Depends on what platform your aiming at!

Specialist Application Programmer
IS Developments
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 8088206
True, I've just gotten so used to using WinXP lately.
0
 

Expert Comment

by:Hume
ID: 8088976
Sorry just had a thought
I use this procedure with a separate trimming procedure to remove the trailing null characters (chr(0))
The following amended code will trim any null chars from the username before returning it


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

Public Function CurrentUserName() As String
   Dim lSize As Long, count As Integer
   Dim sBuffer As String
   sBuffer = String(50, Chr(0))
   lSize = Len(sBuffer)
   Do
       Call GetUserName(sBuffer, lSize)
       count = count + 1
   Loop Until Left(sBuffer, 1) <> Chr(0) Or count >= 3
   CurrentUserName = Left(sBuffer, InStr(1, sBuffer, Chr(0)) - 1)
End Function

Specialist Application Programmer
IS Developments
0
 
LVL 1

Author Comment

by:usafbuttcrack
ID: 8089521
shanesuebsahakarn,

Thanks!  We are running Windows 2000 on all our machines with several 2000 and one NT servers.  Environ is a pretty cool function.  Thanks for letting me know about.  I'll be using it more and more for other things.  

Hume,

I bet your solution would work as well.  My VBA skills suck (gotta take a class or something).  Environ will allow me to select needed records using SQL.

(_|_)
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 8089555
NP, glad I could help! BTW, Hume's function should also work in an SQL query too.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question