Getting the username in windows

Just starting out? Need help? Post your questions and find answers here.
The Mexican
User
User
Posts: 16
Joined: Sat Oct 07, 2006 5:47 pm
Location: Somewhere in Mexico

Getting the username in windows

Post 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:
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

Like this :

Code: Select all

Name.s=Space(500)
NameLen=Len(Name) 
GetUserName_(@Name,@NameLen) 
Debug Name
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Re: Getting the username in windows

Post 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)
Tranquil
Post Reply