Dave Nottage 557 Posted February 7, 2022 I've found some code from an older repo (namely https://github.com/ccy/jedi-apilib) for what I want to achieve however I'm having trouble making it work. This is the code in question: const WTS_CURRENT_SERVER_HANDLE = 0; WTS_CURRENT_SESSION = DWORD(-1); type _WINSTATION_REMOTE_ADDRESS = record AddressFamily: DWORD; Port: WORD; Address: array [0..19] of Byte; Reserved: array[0..5] of Byte; end; PWINSTATION_REMOTE_ADDRESS = ^_WINSTATION_REMOTE_ADDRESS; TWinStationRemoteAddress = _WINSTATION_REMOTE_ADDRESS; PWinStationRemoteAddress = PWINSTATION_REMOTE_ADDRESS; function WinStationQueryInformation(hServer: THandle; SessionId: DWORD; WinStationInformationClass: Cardinal; pWinStationInformation: PVOID; WinStationInformationLength: DWORD; var pReturnLength: DWORD): Boolean; stdcall; external 'winsta.dll' name 'WinStationQueryInformationW'; function GetWVDClientAddress: string; var LBytesReturned: DWORD; LRemoteAddress: _WINSTATION_REMOTE_ADDRESS; begin LBytesReturned := 0; ZeroMemory(@LClientAddress, SizeOf(LClientAddress)); if WinStationQueryInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WinStationRemoteAddress, @LClientAddress, SizeOf(LClientAddress), LBytesReturned) then begin // Do something with LClientAddress here end else Result := SysErrorMessage(GetLastError); end; The call to WinStationQueryInformation is failing, and the message being returned by SysErrorMessage is: "The tag is invalid". Is there something obvious that I'm missing? Share this post Link to post
qubits 20 Posted February 7, 2022 (edited) nothing obvious.. wondering though looks like _WINSTATION_REMOTE_ADDRESS might have changed back in windows 8.1 Noticing that here maybe This showed up in my search too. <-pascal anyways.. and here<- looks like you have to enumerate through all sessions, don't think you can pass -1 Edited February 7, 2022 by qubits add content Share this post Link to post
Dave Nottage 557 Posted February 9, 2022 On 2/8/2022 at 4:22 AM, qubits said: looks like you have to enumerate through all sessions, don't think you can pass -1 That was it; thanks Share this post Link to post
Dave Nottage 557 Posted February 14, 2022 On 2/10/2022 at 9:06 AM, Dave Nottage said: That was it; thanks Unfortunately, this gives the public facing IP address, which makes sense, however in my case isn't suitable. What I am after is a way of obtaining a unique identifier for the "local" machine, by way of either one of the WTS functions or the Winstation functions. Share this post Link to post
qubits 20 Posted February 14, 2022 Searching for Delphi Winsta. I found this. Looks old, but got allot in it. Share this post Link to post
Dave Nottage 557 Posted February 14, 2022 8 minutes ago, qubits said: I found this. I'm aware of that one, but thanks 🙂 We've ended up going with a combination of: WTSUserName WTSDomainName WTSClientName WTSClientAddress https://docs.microsoft.com/en-us/windows/win32/api/wtsapi32/ne-wtsapi32-wts_info_class using WTSQuerySessionInformation 1 Share this post Link to post