Page 1 of 1

Getting the username in windows

Posted: Mon Nov 13, 2006 7:04 am
by The Mexican
After looking at the API I found that the GetUsername function should return the username of the current logged user.

Code: Select all

*mem=AllocateMemory(1000)
buff.w=1000
GetUserName_(*mem,buff)
Debug PeekS(*mem)
FreeMemory(*mem)
After compiling this code I get an "invalid memory access" error.
Please help.:cry:

Posted: Mon Nov 13, 2006 7:14 am
by Droopy
Like this :

Code: Select all

Name.s=Space(500)
NameLen=Len(Name) 
GetUserName_(@Name,@NameLen) 
Debug Name

Re: Getting the username in windows

Posted: Mon Nov 13, 2006 1:21 pm
by Tranquil
The Mexican wrote:After looking at the API I found that the GetUsername function should return the username of the current logged user.

Code: Select all

*mem=AllocateMemory(1000)
buff.w=1000
GetUserName_(*mem,buff)
Debug PeekS(*mem)
FreeMemory(*mem)
After compiling this code I get an "invalid memory access" error.
Please help.:cry:
GetUserName_() requires a pointer to an empty string buffer AND a pointer to the length of this buffer. You need to change your code this way or use droopy's code which is much more handy.

Code: Select all

mem=AllocateMemory(1000)
buff.w=1000
GetUserName_(*mem,@buff)
Debug PeekS(*mem)
FreeMemory(*mem)