Access 2007 Runtime call of Environment Variables in 2008 R2 Server RDS

We run an access application which we compile to a 2007 runtime file for an application on our production floor.  The application pulls the username from the environment variable and uses that username to pull the parameters of the station from a SQL Database.

We run the application on a NLB group of 2008 R2 Remote Desktop Servers.  So, a thin client on the floor connects, logs in as the username of that specific station, the environment variable for username and computername are read, and the station proceeds to load its particulars.

Well, we have a problem periodically where one of the 4 servers, when stations load, they cant get the username, and as such the program cannot load completely.   We end up moving stations off that server, rebooting the server and then moving them back on.  Any stations currently active though work fine, it is only on a fresh login that the stations have issues.  

Further, if we move the session from Server A to Server B for example, it works.  Move it back to A and it doesn't work until a Reboot occurs.

So, my question is:  we use the following two calls for collecting %username% and %Computername%

VBA.Environ("USERNAME")
VBA.Environ("COMPUTERNAME")

Is there a better solution for pulling reliably the username of the logged in user, and the server name that the station is connected to?

Keeping in mind, this is a remote desktop server environment.  It needs to pull the logged in username of that session, not of the console or anything like that.

Any suggestions would be greatly appreciated.

Paul
LVL 5
TheMetalicOneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Paste the code below into a module and then call WhoAmI(True) to return the user name or (false) to return the computer name.

Jim.

Private Declare Function GetComputerNameA Lib "kernel32" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetUserNameA Lib "advapi32.dll" (ByVal lpBuffer As String, nSize As Long) As Long


Public Function WhoAmI(bReturnUserName As Boolean) As String

        ' Function returns either user name or computer name

        Dim strName As String * 255

10      If bReturnUserName = True Then
20        GetUserNameA strName, Len(strName)
30      Else
40        GetComputerNameA strName, Len(strName)
50      End If

60      WhoAmI = left$(strName, InStr(strName, vbNullChar) - 1)

End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TheMetalicOneAuthor Commented:
Thanks, we used chunks of the code and accomplished our goals.  Much appreciated!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Server OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.