I'm using C# Winforms and I'm trying to get the user name that currently logged on a speitific computer on the domain. I can achieve it by opening CMD with administrator privileges, and then type this line:
wmic.exe /node:(computername or ip address) computersystem get username
The result is:
UserName
Domain\real-user-name
However, I wants to get only the "real-user-name"
. How can I get it without substring, via WMIC?
As Am_I_Helpful mentioned in the comments, it is too good and important that the result of the wmic command
is with a domain name.
Therefore, probably, the only option to get only the username is by using substring()
method on the wmic command output.