Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / How to get the windows %username%

Author
Message
billy777
23
Years of Service
User Offline
Joined: 9th Jan 2003
Location:
Posted: 8th Aug 2007 08:16
Is there anyway to get the %username% from the user logged into windows - I did a search but could not find anything about this.

I am probably going to have to use some sort of windows api to extract the username somehow... but I am not sure of the exact syntax on how to do this.

Any help would be greatly appreciated.

Thanks
Bill
Insert Name Here
19
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 8th Aug 2007 11:40
I'm sure there's a dll somewhere that could do this, I don't know anything specific though.

I never tell the truth.
That ain't a paradox.
I always tell lies is though.
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Aug 2007 20:28 Edited at: 9th Aug 2007 20:39
If you are using DBC, you'll need the enhanced version. You'll also need to know a little bit about memblocks.

[EDIT]
In this example, I originally create buffer that will return the user name to a maximum of 200 characters. This could adjusted to your needs:
Make Memblock 1,200

But right after I wrote it, I remembered that DBC sends the pointer of a string to a dll so I could just use a string variable instead. But if I want more that 255 characters or I want to limit the number of characters, I could use a memblock to store the buffer. The version I'm posting here will be with a string variable instead of memblock 1 because it's just a little bit easier.

Memblock 2 is just a pointer to a DWORD which is where I store the length of the previously defined buffer for the user name. I make the memblock 4 bytes in length, then set it's value to the length of the buffer (200).

The name is returned in lpBuffer$

If result is 0, then the call failed.



Enjoy your day.

Login to post a reply

Server time is: 2026-07-06 06:44:48
Your offset time is: 2026-07-06 06:44:48