Terminal ID

Samj

Member
Is there an API I could use to identify the name of the device the user is working on? I found the Progress code on http://www.global-shared.com/ for the GetUserName API and I can get the user's network logon, but I need to know the device name especially for Remote Desktop Connections from PC's.

Progress 8.3E, Windows 2000 Server, Windows XP Clients.

Thanks,

Sam
 
You can use GetComputerName to get device name of current system - Perhaps remote systems could pass this in as a parameter.

Code:
procedure GetComputerNameA external "kernel32.dll":
    def input parameter lpBuffer as memptr no-undo.
    def input-output parameter nSize as long no-undo.
    def return parameter opl_Status as long no-undo.
end procedure.
 

Samj

Member
Tried this...

I tried the GetComputerName function. It works fine for what we call a 'thick' client. But with terminal server or remote desktop connections from a PC or with a Nutshell or ThinSTAR terminal it returns the servers name. I was really wanting to get something similar to a unix tty ID.
 

Samj

Member
Thanks

That worked like a champ! Now I find I've asked for the wrong thing. I need Client Name.
 

Samj

Member
Okay...

I've found: WTSQuerySessionInformation

It's supposed to return Client Name.

Where do I find values for:
WTS_CURRENT_SERVER_HANDLE,
WTS_CURRENT_SESSION and
WTS_INFO_CLASS:WTSClientName ?

Thanks,

Sam
 

Samj

Member
Ok

I do have ProcessIdToSessionId in the code although I thought I could use the value -1 to indicate the current session. I don't have WTSOpenServer in the code I again 'thought' I could use the value 0 for the server handle.

I had already found that link on WTS_INFO_CLASS and WTSQuerySessionInformation, what I don't understand there is the structure or the size to set the memptr. And I don't know how I go about getting the WTSClientName value out of it. I was guessing that WTSClientName would need to be hard coded or defined as a preprocessor value.


Am I totally off base here? I not very adept at translating the C++ function calls into Progress. I did manage to get two of them, GetCurrentProcessId and ProcessIdToSessionId, to work though.
 

bendaluz2

Member
Pointer Example

<code>
DEFINE VARIABLE ptr$name AS MEMPTR.
DEFINE VARIABLE c$client-name AS CHARACTER NO-UNDO.

SET-SIZE(ptr$name) = &ltMax Length of Client Name&gt + 1.

RUN WTSQuerySessionInformation
&nbsp;&nbsp;(hServer,
&nbsp;&nbsp; SessionID,
&nbsp;&nbsp; GET-POINTER-VALUE(ptr$name),
&nbsp;&nbsp; ppBuffer,
&nbsp;&nbsp; pBytesReturned).

ASSIGN c$client-name = GET-STRING(ptr$name,0).

SET-SIZE(ptr$name) = 0.

</code>
 

Samj

Member
This is what I found out...

If anyone is interested.

PROCEDURE GetComputerNameA EXTERNAL "kernel32.dll":
DEFINE OUTPUT PARAMETER lpBuffer AS MEMPTR.
DEFINE INPUT-OUTPUT PARAMETER nSize AS LONG.
DEFINE RETURN PARAMETER intResult AS SHORT.
END PROCEDURE.

PROCEDURE ProcessIdToSessionId EXTERNAL "kernel32.dll":
DEFINE INPUT PARAMETER dwProcessId AS LONG.
DEFINE OUTPUT PARAMETER pSessionId AS MEMPTR.
DEFINE RETURN PARAMETER intResult AS SHORT.
END PROCEDURE.

PROCEDURE GetCurrentProcessId EXTERNAL "kernel32.dll":
DEFINE RETURN PARAMETER intResult AS SHORT.
END PROCEDURE.

PROCEDURE WTSQuerySessionInformationA EXTERNAL "Wtsapi32.dll":
DEFINE INPUT PARAMETER hServer AS LONG.
DEFINE INPUT PARAMETER SessionId AS LONG.
DEFINE INPUT PARAMETER WTSInfoClass AS LONG.
DEFINE OUTPUT PARAMETER ppBuffer AS LONG.
DEFINE OUTPUT PARAMETER pBytesReturned AS LONG.
DEFINE RETURN PARAMETER intResult AS LONG.
END PROCEDURE.

FUNCTION FuncClientName RETURNS CHARACTER
( /* parameter-definitions */ ) :
/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/
DEFINE VARIABLE lpInfoClass AS INTEGER NO-UNDO.
DEFINE VARIABLE lpName AS MEMPTR NO-UNDO.
DEFINE VARIABLE ws-client-name AS CHARACTER NO-UNDO.
DEFINE VARIABLE BytesReturned AS INTEGER NO-UNDO.
DEFINE VARIABLE intResult AS INTEGER NO-UNDO.

RUN WTSQuerySessionInformation{&A}(INPUT 0, /* {&WTS_CURRNET_SERVER_HANDLE} */
INPUT -1, /* {&WTS_CURRENT_SESSION} */
INPUT 10, /* {&WTS_CLASS_INFO} */
OUTPUT lpInfoClass,
OUTPUT BytesReturned,
OUTPUT intResult).
SET-POINTER-VALUE(lpName) = lpInfoClass.
ASSIGN
ws-client-name = GET-STRING(lpName,1).
SET-SIZE(lpName) = 0.
RETURN (ws-client-name). /* Function return value. */
END FUNCTION.

FUNCTION FuncGetCurrentProcessId RETURNS INTEGER
( /* parameter-definitions */ ) :
/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/
DEFINE VARIABLE dwProcessId AS INTEGER NO-UNDO.

RUN GetCurrentProcessId(OUTPUT dwProcessID).

RETURN (dwProcessId). /* Function return value. */
END FUNCTION.

FUNCTION FuncProcessIdToSessionId RETURNS INTEGER
( /* parameter-definitions */ ) :
/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/
DEFINE VARIABLE dwProcessId AS INTEGER NO-UNDO.
DEFINE VARIABLE lpSession AS MEMPTR NO-UNDO.
DEFINE VARIABLE intResult AS INTEGER NO-UNDO.

SET-SIZE(lpSession) = 8.
RUN ProcessIdToSessionId(INPUT FuncGetCurrentProcessID(),
OUTPUT lpSession,
OUTPUT intResult).
IF intResult <> 0 THEN
ASSIGN
dwProcessId = GET-LONG(lpSession,1).
SET-SIZE(lpSession) = 0.
RETURN (dwProcessId). /* Function return value. */
END FUNCTION.

FUNCTION GetComputerName RETURNS CHARACTER
( /* parameter-definitions */ ) :
/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/
&Scoped-define MAX_COMPUTERNAME_LENGTH 16

DEFINE VARIABLE iResult AS INTEGER NO-UNDO.
DEFINE VARIABLE iBufferSize AS INTEGER INITIAL {&MAX_COMPUTERNAME_LENGTH} NO-UNDO.
DEFINE VARIABLE lpToString AS MEMPTR NO-UNDO.
DEFINE VARIABLE cComputerName AS CHARACTER NO-UNDO.

SET-SIZE(lpToString) = {&MAX_COMPUTERNAME_LENGTH}.
RUN GetComputerNameA(OUTPUT lpToString,
INPUT-OUTPUT iBufferSize,
OUTPUT iResult).
IF iResult = 1 THEN
ASSIGN
cComputerName = GET-STRING(lpToString,1).
SET-SIZE(lpToString) = 0.
RETURN (cComputerName).
END FUNCTION.

GetComputerName() - returns the name of the server.

FuncProcessIdToSessionId() - returns the session id, won't be the same number each time you log on.

FuncClientName() - returns the device name whether it's a PC running remote desktop or teminal server or a ThinSTAR/Nutshell 'smart'-terminal

Thanks bendaluz, Simon, Jurjen and Frank Kim @ Microsoft for all your help and suggestions in getting me through this.

Sam
 

bendaluz2

Member
Sorry, didnt notice that lpInfoClass was a pointer to the returned data and not the data itself. Hope I didnt send you down the wrong path too much :)
 
Top