views:

416

answers:

1

Hi All, I'm trying gather Terminal Server session information on 64-bit Windows machines. My question is two fold. First, on 32-bit machines we called the following function, which worked fine.

Private Declare Function WTSQuerySessionInformation Lib "wtsapi32" _
                  Alias "WTSQuerySessionInformationA" _
                 (ByVal hServer As Integer, _
                  ByVal SessionID As Integer, _
                  ByVal WTSInfoClass As Integer, _
                  ByRef ppBuffer As String, _
                  ByRef lLen As Integer) As Integer

On 64-bit machines however this function call fails. Does anyone have any idea's about how to fix this? I googled around, but couldn't find much about calling this function on a 64 bit machine. Second, does anyone know any other options for getting TS Client Session Info? Specifically I need the Computer Name that is accessing the TS.

Thanks a lot for the help.

+1  A: 

How exactly is the call failing on the 64-bit machine? My guess is that it has something to do with the fact that you are calling the ANSI version of the function. Perhaps you'd have better luck with the Unicode version (WTSQuerySessionInformationW).

But to answer your second question, you might try using Cassia so that you don't have to deal with the P/Invokes:

New Cassia.TerminalServicesManager().CurrentSession.ClientName

I can't remember if I've tried it on a 64-bit machine before, but if it works, it may make things a bit easier for you.

EDIT: Just tested Cassia on a 64-bit Windows Server 2008 R2 beta machine, and it works fine.

Dan Ports
Dan, you were correct. I needed to use the Unicode Version
Charlie White