Get full username for new username

When using NetUserAdd, the user will be created on the local computer or as a domain account, depending on the role of the server on which you used this feature.

I want to get the full username (LOCALCOMPUTER \ USERNAME or DOMAIN \ USERNAME) in order to use it remotely.

Is there a function for this?

+1


a source to share


2 answers


Caveat: I haven't tested the solution. You can call NetGetJoinInformation to see if the device belongs to the domain and NetServerGetInfo if the code is running on a DC. After this test, you can get the machine name (GetComputerName) and domain name (NetWkstaGetInfo) and whatever you need.



Be careful when doing this in a cluster.

+2


a source


I'm sure I'm missing something, but you can't use GetUserNameEx

and pass what you want EXTENDEND_NAME_FORMAT

? I believe there NameSamCompatible

should be a desired format.



You will return either to MachineName\UserName

orDomainName\UserName

+1


a source







All Articles