Consultor Eletrônico



Kbase P50790: How to Call WIN32 API Function: GetUserName
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/02/2004
Status: Unverified

GOAL:

How to Call WIN32 API Function: GetUserName

FIX:

DISCLAIMER:
===========
The code example in this knowledgebase is for informational purposes
only. If you have specific questions about which API calls would be
best suited to your design goals, please consult your Microsoft
documentation.

INTRODUCTION:
=============
The following sample code shows how to call the Win32 API function
called GetUserName.
This function returns the UserID used to logon to Windows.

This code has been tested on Windows NT 4.0 Workstation only.

DEFINE VARIABLE chrUserID AS CHARACTER NO-UNDO.
DEFINE VARIABLE intResult AS INTEGER NO-UNDO.
DEFINE VARIABLE intSize AS INTEGER NO-UNDO.

PROCEDURE GetUserNameA EXTERNAL "ADVAPI32.DLL":
DEFINE OUTPUT PARAMETER chrUserID AS CHARACTER NO-UNDO.
DEFINE INPUT-OUTPUT PARAMETER intBufferSize AS LONG NO-UNDO.
DEFINE RETURN PARAMETER intResult AS SHORT NO-UNDO.
END PROCEDURE.

ASSIGN chrUserID = FILL(' ',256)
intSize = 255.

RUN GetUserNameA (OUTPUT chrUserID,
INPUT-OUTPUT intSize,
OUTPUT intResult).

IF intResult = 1 THEN
DO:
MESSAGE "Logon ID = " TRIM(chrUserID) VIEW-AS ALERT-BOX.
END.
ELSE
MESSAGE "Buffer Was Not Large Enough" VIEW-AS ALERT-BOX.