Link to home
Start Free TrialLog in
Avatar of frimy
frimyFlag for United States of America

asked on

Access 2010 get Name of local computer from Terminal server

Hello ALL,
How do i get the local computers Name using terminal server.
VBA.Environ("computername"), will give the Server Name,
I need the name of the local computer that is connected to the server.
Thanks in advance
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

So .. you are logged in via TS and you need the name(s) of computers connected to that server ?
Avatar of frimy

ASKER

Yes Sir,
Avatar of crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access

you should be able to use a Windows API.

at the top of the module, below the Option statements :
#If VBA7 Then           '  Code is running in the VBA7 editor
   Private Declare PtrSafe Function apiGetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#Else                   ' Code is running in VBA version 6 or earlier
  Private Declare Function apiGetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If

Open in new window

then here is a function that will return the computer name as a string:
Private Function GetComp() As String
'161220 s4p
   On Error GoTo proc_err
   Dim sBuffer As String _
      , nLen As Long _
      , nSize As Long
    nLen = 16
    sBuffer = String$(nLen, 0)
    nSize = apiGetComputerName(sBuffer, nLen)
    
    If nSize <> 0 Then
        GetComp = Left$(sBuffer, nLen)
    Else
        GetComp = ""
    End If
proc_exit:
   On Error Resume Next
   Exit Function
  
proc_err:
   Resume proc_exit
   Resume
End Function

Open in new window

Crystal ... but doesn't that really return the same thing as Environ ("ComputerName") ... although I never use Environ any more.
Joe, on my machine, it does -- but on a terminal, perhaps it will get what frimy needs instead of the name of the server.

frimy, if this does not work (will you test it? I'd like to know, thanks), perhaps you can use the Windows user name?
You may have a look: https://arstechnica.com/civis/viewtopic.php?t=174084 

I found something not sure this will help you..
ASKER CERTIFIED SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Either of the last two will work.  apiGetComputerName would still return the name of the server.

Jim.
So  Environ("clientname") only works on what ?
It returns blank on my laptop .... just curious
Only if you have an RDP session going and you execute SET within that session:

User generated image
Jim.
Avatar of frimy

ASKER

this worked for me from als315
Environ("clientname")
Thanks
frimy, while I was glad to help, the best answer was given by als315 (the post with all the Likes!).  You can click ... below your original post and Request Attention to re-open the question to close again and redistribute the points awarded.

https://www.experts-exchange.com/questions/29006857/Access-2010-get-Name-of-local-computer-from-Terminal-server.html?anchorAnswerId=42035434#a42035434
Avatar of frimy

ASKER

I already posted the points to als315 and closed the question.
I don't know why the question was still open.
I didn't see the option to Request Attention and I just wanted to close the question.
>" posted the points to als315 "

actually, no ... You picked one of my posts as the best solution.

Please try your best to picked good posts for a solution when you "close" a question.  You can re-open a question to mark the proper post as the best solution.  You can also mark other posts you found helpful as Assisted.  In addition to  acknowledging those who  helped, others that lookup this topic will  find the answer to the question you asked, or good words for thought, in the post(s) that you picked for the answer.

thanks ~
> "didn't see the option to Request Attention"

look below your original post for the [ ... ] button.  

( ... usually means more choices )
Avatar of frimy

ASKER

thank you
Avatar of frimy

ASKER

Thanks this worked for me and it was very simple what I like.
Have a nice weekend