Monday, April 23, 2012

Windows API – Get Windows User

Use windows api to get the username.
Declare in the Global External Functions

Function boolean GetUserNameA( ref string userID, ref ulong len ) library "ADVAPI32.DLL" ALIAS FOR "GetUserNameA;ansi"
Function boolean GetUserName(Ref String lpBuffer, Ref Ulong nSize) Library "ADVAPI32.DLL" ALIAS FOR "GetUserNameW"
*ALIAS FOR "GetUserNameA;ansi" - NEED TO CALL ALIAS IF NOT the string return contains garbage.


To use this function in powerscript


 string  login_name
 string  ls_temp
 ulong   lul_value
 boolean lb_rc

 lul_value = 255
 ls_temp = Space( 255 )
 lb_rc = GetUserNameA( ls_temp, lul_value )
 login_name = Trim( ls_temp )

No comments:

Post a Comment