Jump to content

get Hostname of the Client connected to the TerminalServer session


JRSmile
 Share

Recommended Posts

This Function gets the Hostname of the Client on the Terminal Server,

can be used to determine the correct std printer near the location of the client while working on the terminal server session.

Func _GetWTSClientName($sid)
Local $result = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformation", "Ptr", 0, "int", $sid, "int", 10, "ptr*", 0, "dword*", 0)
If @error Or $result[0] = 0 Then Return SetError(1, 0, "")
Local $ip = DllStructGetData(DllStructCreate("byte[" & $result[5] & "]", $result[4]), 1)
DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr", $result[4])
Return StringReplace(BinaryToString($ip), Chr(0), "")
EndFunc   ;==>_GetWTSClientName

Best regards,

J

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Link to comment
Share on other sites

  • 3 weeks later...

What do you mean by "this doesn't work"?

Do you get an invalid result? Do you get an error message? Does your script crash? What operating system does the client run? 32/64 bit? What operating system does the terminal server run? Etc. etc.

Please be more specific - just: "doesn't work" isn't enough to solve a problem

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

What do you mean by "this doesn't work"?

Do you get an invalid result? Do you get an error message? Does your script crash? What operating system does the client run? 32/64 bit? What operating system does the terminal server run? Etc. etc.

Please be more specific - just: "doesn't work" isn't enough to solve a problem

you are right, my fault.

anyway, the doesn't work means there's just " " returned. or maybe anyone has the example for the function?

Link to comment
Share on other sites

Im Sorry that i have Witten so less about the Funktion, but i just found it in an Archive of Mine an thought ist could be usefull for you guys, the Funktion returns the hostname if the Client Computer which is connected via rdp on a terminal Server Session, the function Must be called with the credentials of the User currently logged on and be executed on the terminalserver itself.

I use it like $hostname = wtsgetclientname()

$username= @username

And like so you can determine the connected User and the connected client.

Best Regards, JR

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Link to comment
Share on other sites

Ps.: typing english on a german iPad sucks ....

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Link to comment
Share on other sites

Regreat to say that still could not understand the function...and you said, the function must be called with the credentials of the user currently logged on.. but if I, for example:

1. Used User UID1 logon the Server SRV1 from machine PC1

2. Can call the function from PC2 with User UID2 (UID2 is also in the SRV1's local administrators group) to check who has logged on the SRV1 and from Which client?

Im Sorry that i have Witten so less about the Funktion, but i just found it in an Archive of Mine an thought ist could be usefull for you guys, the Funktion returns the hostname if the Client Computer which is connected via rdp on a terminal Server Session, the function Must be called with the credentials of the User currently logged on and be executed on the terminalserver itself.

I use it like $hostname = wtsgetclientname()

$username= @username

And like so you can determine the connected User and the connected client.

Best Regards, JR

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...