@winapi

Apr 13, 2010
236
3
58
The Hague
#1
Using:
TCC 16.03.55 x64 Windows 8.1 [Version 6.3.9600]
TCC Build 55 Windows 8.1 Build 9600

See also
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724435(v=vs.85).aspx

The following call should return the full user name.
GetUserNameEx(3) is implemented in Secur32.dll

Works with the following python code:
Code:
>>> import win32api
>>> print(win32api.GetUserNameEx(3))
Using @WINAPI[] however, I fail to get the desired string.

I have studied the docs but and tried as many variants as I could think of but none of them work.
Also, I must admit, I fail to fully understand the syntax of the "BUFFER thingy". When to use and how to use it.

I would appreciate some clarification.

Regards, DJ
 
#3
Apparently it only works with NameFormat = NameSamCompatible = 2.
Code:
v:\> do i=0 to 12 (echo %@winapi[secur32.dll,GetUserNameEx,%i,BUFFER,PDWORD=256])
ECHO is OFF
ECHO is OFF
zz\vefatica
ECHO is OFF
ECHO is OFF
ECHO is OFF
ECHO is OFF
ECHO is OFF
ECHO is OFF
ECHO is OFF
ECHO is OFF
ECHO is OFF
ECHO is OFF
This also works.
Code:
v:\> echo %@winapi[advapi32.dll,GetUserName,BUFFER,PDWORD=256]
vefatica
If a [a]BUFFER is specified, %WINAPI will output the contents of the buffer (instead of the return value of the function).
 
Likes: djspits
#4
Apparently it only works with NameFormat = NameSamCompatible = 2.
.... which is very peculiar since, in an EXE, this code,
Code:
    for ( INT i=0; i<13; i++ )
    {
      GetUserNameEx((EXTENDED_NAME_FORMAT) i, szUserName, &(size=256));
      wprintf(L"%s\n", szUserName);
    }
which includes some non-existing formats, produces the following (which includes some odd results)! I have no idea what "lume11" is.
Code:
lume11\Projects\test\Release\test.exe
lume11\Projects\test\Release\test.exe
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
 
Apr 13, 2010
236
3
58
The Hague
#5
Thanks very much, guys. You solved a long standing problem.

Would you agree with me that the help could use some improvements? A few examples perhaps?

I mean, I'm very impressed with the apparent ease with which you seem to have decoded the syntax definition of this function, but I wasn't and I'm pretty sure many other customers won't be able to do that.

Regards, DJ
 
#6
.... which is very peculiar since, in an EXE, this code,
Code:
    for ( INT i=0; i<13; i++ )
    {
      GetUserNameEx((EXTENDED_NAME_FORMAT) i, szUserName, &(size=256));
      wprintf(L"%s\n", szUserName);
    }
which includes some non-existing formats, produces the following (which includes some odd results)! I have no idea what "lume11" is.
Code:
lume11\Projects\test\Release\test.exe
lume11\Projects\test\Release\test.exe
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
zz\vefatica
I had that wrong (printing an uninitialized/leftover string when the function failed). If I clear the string every time (as I should have) this function works only when the format arg is 2.