Re: Win32Lib getUserName() problem
- Posted by AndyDrummond Dec 16, 2009
- 1459 views
mattlewis said...
AndyDrummond said...
Is there any way that anyone knows whereby I can get the current user's name, rather than the name the current account was created with?
I'm not sure what Win32Lib is doing, exactly, but you might want to take a look at GetUserNameEx. There appear to be many different ways to get a name:
typedef enum { NameUnknown = 0, NameFullyQualifiedDN = 1, NameSamCompatible = 2, NameDisplay = 3, NameUniqueId = 6, NameCanonical = 7, NameUserPrincipal = 8, NameCanonicalEx = 9, NameServicePrincipal = 10, NameDnsDomain = 12 } EXTENDED_NAME_FORMAT, *PEXTENDED_NAME_FORMAT;
Matt
Matt,
I am having trouble with this. Can you cast your eye over this and see why it fails,please?
constant advapi32 = registerw32Library("advapi32.dll"), -- common dialogs xGetUserNameEx = registerw32Function(advapi32, "GetUserNameExA", {C_INT, C_POINTER, C_POINTER}, C_INT) global function getUserNameEx(integer format) sequence lUserId atom lBufferAddress, lResultCode lBufferAddress = w32acquire_mem(0, 4 + 256 + 1) poke4(lBufferAddress, 256) lResultCode = w32Func(xGetUserNameEx, {format, lBufferAddress+4, lBufferAddress}) if lResultCode then lUserId = w32peek_string(lBufferAddress+4) else lUserId = {} end if w32release_mem(lBufferAddress) return lUserId end function
I tried C_LONG rather than C_INT just in case; same "klonk!" and failure when the w32Func call is made. I copied the code from Win32Lib's getUserName() with enhancements. The value of xGetUserNameEx is valid looking. I called with format equal to 1.....
Win32 interfacing is definitely NOT my stromg point.
Andy