LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get hostname from APP executed in RDS (not server name, but local PC name)

Hello,

Is there a way to get hostname from PC wich is connected to a RDS where a LabVIEW app is running?

 

Example: PC123 is connected to SERVER123 where a virtual machine is running an APP. The app should be able to get PC123 name.

If I try this: SerP_0-1710764038546.png  (Which it works with local apps and PC) I will get SERVER123 name, as this is the host for application. But I need to get the name of the PC connected to the remote desktop.

 

Thanks a lot!

 

0 Kudos
Message 1 of 6
(322 Views)

You would do it the same way as without LabVIEW. The question intrigued me, so I looked it up myself. This seems quite promising:

 

https://superuser.com/questions/393203/get-hostname-of-a-rdp-client-computer

 

On the server, after connecting, open up console and see if

netstat -na | find "3389" | find "ESTABLISHED"

gives you the result you are after. If you control the server, this is probably good enough.

 

Since there is also the PowerShell line of

(Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational';ID=1149;StartTime=(Get-Date).AddDays(-31);} | ForEach-Object {[PSCustomObject] @{User=$_.Properties[0].Value;ClientName=$_.Properties[1].Value;IPAddress=$_.Properties[2].Value; TimeCreated=$_.TimeCreated;}} | Where-Object User -eq $env:USERNAME | Sort-Object -Property TimeCreated -Descending | Select-Object -First 1).ClientName

making use of windows events, it can probably be done with .NET nodes also, which would be a bit more robust.

0 Kudos
Message 2 of 6
(269 Views)

Hello  LLindenbauer,

Thanks for the info.

Ive been trying it but I can not manage to get any name. I just get the DNS name.

I will keep investigating this approach, but I was thinking more of a LabVIEW code than a Windows code.

0 Kudos
Message 3 of 6
(228 Views)

Well, as far as LabVIEW is concerned it is running on the server and has no idea that you run it through an RDS connection from a computer.

You would have to approach it from the point of view of an app running on the server to find out from which computer the connection comes, which LLindenbauer sort of gave you but in a likely non-robust way if more than one RDS connection to the server exists. Then from there query the computer name of that computer address.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 6
(223 Views)

Hello Rolfk,

Ok, I understand what you say. 

Unfortunately, I have no administrator privileges on the server, so I have limited resources to do some test.

Anyway, I really appreciate your comments

0 Kudos
Message 5 of 6
(208 Views)

You may have to dig into calling Windows APIs.

 

One way to detect if you are in a terminal session seems to be to query the "SessionName" environment variable. If that returns anything you are executing in a terminal session. The name can then be used to query various attributes of the session.

 

The Windows Terminal Session API may be required for the real work. https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/

This lets you query all kinds of things about if and what the current terminal session is. There are likely .Net interfaces to this functionality too.

 

WTS_CLIENT_ADDRESS address = {0};
BOOL success = WTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientAddress, &address, sizeof(WTS_CLIENT_ADDRESS);
if (success)
{
   switch (address.AddressFamily)
   {
        case AF_INET:
           IpAddress = *(uint32_t*)(address.Address + 2);
           break;
       case AF_INET6:
           Ip6Address = address.Address;
           break;
}
else
{
    // Not in a terminal session
}
Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 6
(202 Views)