zpanderson Posted June 25, 2012 Posted June 25, 2012 I have 4 thin client servers that are connected to a load balancer. thin_client1 thin_client2 thin_client3 thin_client4 load_balancer When I RDP to the load_balancer it picks one of the 4 thin_clients and redirects the rdp to that server. My question is; is there any way for me to tell which server I get connected to? Thanks!
UEZ Posted June 25, 2012 Posted June 25, 2012 Try hostname.exe on the appropriate server to get the server name you are logged in.Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
zpanderson Posted June 25, 2012 Author Posted June 25, 2012 Is there a way to remotely run that without knowing the server name already?
zorphnog Posted June 25, 2012 Posted June 25, 2012 (edited) You should be able to retrieve the hostname from the window title. $$sComputer = _GetRemoteConnectionTitle() MsgBox(4096, "Remote Computer Name", $sComputer) Func _GetRemoteConnectionTitle() $sTitle = WinGetTitle("[CLASS:TscShellContainerClass]") $aResult = StringRegExp($sTitle, "(?i)(.+)s-sremote desktop connection", 3) If @error Then Return SetError(1, 0, "") Return $aResult[0] EndFunc Edited June 25, 2012 by zorphnog
zpanderson Posted June 25, 2012 Author Posted June 25, 2012 You should be able to retrieve the hostname from the window title. $$sComputer = _GetRemoteConnectionTitle() MsgBox(4096, "Remote Computer Name", $sComputer) Func _GetRemoteConnectionTitle() $sTitle = WinGetTitle("[CLASS:TscShellContainerClass]") $aResult = StringRegExp($sTitle, "(?i)(.+)s-sremote desktop connection", 3) If @error Then Return SetError(1, 0, "") Return $aResult[0] EndFunc This won't work as I'm going through a load balancer; the load balancer name appears in the rdp title.
BrewManNH Posted June 25, 2012 Posted June 25, 2012 Have you tried running hostname.exe on the server you're connected to? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
zpanderson Posted June 25, 2012 Author Posted June 25, 2012 Have you tried running hostname.exe on the server you're connected to?Yes, I can run hostname manually in the rdp window but I do not see a way to do this through script?
BrewManNH Posted June 25, 2012 Posted June 25, 2012 You'd have to run the script on the server you're connected to. Unless the load balancer has some way of telling you which server it chooses, then you're limited to running the scripts on the server itself. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
zpanderson Posted June 25, 2012 Author Posted June 25, 2012 You'd have to run the script on the server you're connected to. Unless the load balancer has some way of telling you which server it chooses, then you're limited to running the scripts on the server itself.Yeah, that was my initial thought but I was hopeful someone here would have some alternative. The reason I was trying to do this is because I have a script that starts x number of remote desktop sessions and then schedules a task (another script) to start on that remote session (why I need the hostname). Guess I'll have to figure out another way of doing it!Thanks for the responses.
zorphnog Posted June 25, 2012 Posted June 25, 2012 There are several WMI classes you can use with Remote Desktop Connection Broker (Terminal Services Session Broker) if that is what your load balancing server is. Perhaps using WMI and the Win32_SessionDirectorySession on the load balancing server? One caveat to querying a session though. Something like:Dim $objWMIService, $oSessions $objWMIService = ObjGet("winmgmts:.rootcimv2") If @error Then MsgBox(4096, "RDP Session", "ERROR - Could not get WMIService.") Exit(1) EndIf $oSessions = $objWMIService.ExecQuery("SELECT * FROM Win32_SessionDirectorySession WHERE UserName='<UserName>' AND DomainName='<DomainName>'") If IsObj($oSessions) Then For $oSessItem In $oSessions $sMsg = StringFormat("ServerIPAddress: %snServerName: %snSessionID: %snSessionState: %sn", _ $oSessItem.ServerIPAddress, $oSessItem.ServerName, $oSessItem.SessionID, $oSessItem.SessionState) MsgBox(4096, "RDP Session", $sMsg) Next Else MsgBox(4096, "RDP Session", "ERROR - Session query execution failed.") EndIf $oSessions = 0 $objWMIService = 0
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now