Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Getting username under windows

From: th72:dds:nl at: 18-Mar-2007 22:49

Hi List, I'am trying to get the the current username under windows. After a little searching I found the the following api call: BOOL GetUserName( LPTSTR lpBuffer, LPDWORD lpnSize ); In REBOL I tried the following: lib: load/library %advapi32.dll ; no error user: make routine! [arg1 [string!] agr2 [integer!] return: [integer!]] lib "GetUserNameA" ; no error name: make string! 1000 buffersize: 1000 user name buffersize ; crashes rebol After hitting <enter> rebol crashes. I tried different values for name and buffersize. I tried arg2 as string! type. Rebol then stops crashing but no name or anything else is returnt. Can someone give me a hint on what I 'am doing wrong? Or maybe is there some other way to get the current user who is logged in? Thanks Tim I have included the official MS info: Parameters lpBuffer [out] A pointer to the buffer to receive the user's logon name. If this buffer is not large enough to contain the entire user name, the function fails. A buffer size of (UNLEN + 1) characters will hold the maximum length user name including the terminating null character. UNLEN is defined in Lmcons.h. lpnSize [in, out] On input, this variable specifies the size of the lpBuffer buffer, in TCHARs. On output, the variable receives the number of TCHARs copied to the buffer, including the terminating null character. If lpBuffer is too small, the function fails and GetLastError returns ERROR_INSUFFICIENT_BUFFER. This parameter receives the required buffer size, including the terminating null character. If this parameter is greater than 32767, the function fails and GetLastError returns ERROR_INSUFFICIENT_BUFFER. Return Value If the function succeeds, the return value is a nonzero value, and the variable pointed to by lpnSize contains the number of TCHARs copied to the buffer specified by lpBuffer, including the terminating null character.