Use WINAPI to get domain

I can use WINAPI to get the user name of the current user. i.e. WNetGetUser(ULONG,*CSTRING,*ULONG),LONG,RAW,PASCAL,NAME(‘WNetGetUserA’)

However that does not tell me what domain they are in. i.e. it returns jcooke, and not myEnterprise\jcooke.

What do I use for that? I suspect it is GetComputerNameExA, and if it is, what is the prototype and usage of that? It is similar to GetComputerName, which is done like this:

GlobalMap:
MODULE(‘WINAPI’)
GetComputerName(*CString,*ULong),signed,raw,pascal,NAME(‘GetComputerNameA’),PROC
OC

END
My Code
ComputerName CSTRING(255)
ComputerNameLen ULONG(255)
Code
GetComputerName(ComputerName,ComputerNameLen)
Message(ComputerName)

Any ideas here?

This doesn’t answer your question, but is it easier to use the USERDOMAIN environment variable?

Very pragmatic answer here, thanks Paul!
This is what I did at the end:
IF WNetGetUser(GWUN:Local,GWUN:User,GWUN:FieldSize)
GLO:CurrentLogin=‘Invalid’
ELSE
EnvVarName = ‘USERDOMAIN’
GetEnvironmentVariable(EnvVarName, EnvVarValue, SIZE(EnvVarValue))
GLO:CurrentLogin=EnvVarValue & ‘’ & GWUN:User
End

1 Like

I’m guessing, my C6 VM isn’t working at the moment, you could do something like this:

! GetComputerNameEx(Word,Long,Long),Bool,Pascal,Name(‘GetComputerNameExA’)

ComputerNameNetBIOS equate(1)
ComputerNameDnsHostname equate
ComputerNameDnsDomain equate
ComputerNameDnsFullyQualified equate
ComputerNamePhysicalNetBIOS equate
ComputerNamePhysicalDnsHostname equate
ComputerNamePhysicalDnsDomain equate
ComputerNamePhysicalDnsFullyQualified equate
ComputerNameMax equate

var1 cstring(300)
var2 long
ec long
code
var2 = size(var1)
ec = GetComputerNameEx(ComputerNameDnsFullyQualified,address(var1),var2)
if ec = 0 then
clear(var2)
end