About Environment.UserDomainName

  • Thread starter Thread starter Lau Lei Cheong
  • Start date Start date
L

Lau Lei Cheong

Hello,

I'm writing a .NET v1.1 Windows Application which will try to determine
current username by Environment.UserDomainName + "\\" +
Environment.UserName. This approach works in normal condition if I run it
directly. (returns "<DomainName>\<Username>")

But if I use the program with RunAs.exe, let's say run with
"<DomainName>\Administrator" account, it'll return
"<MachineName>\administrator" instead.

Can anyone suggest what I should use to determine the current username?

Regards,
Lau Lei Cheong
 
This is probably because you are running the program as the local computer
admin, and you are not connected to a domain at the time. There is no way to
detect the domain when you're not connected to one.
 
No. I'm currently connected to the domain, and I'm sure the connection to
Domain Controller is Ok (This is obvious, I can't use runas to run something
as Domain Administrator if I can't anthenicate against the domain server. As
I won't normally logon my desktop with that identity, my desktop can't
possibly have cached the password).

Anyway, I've find the
System.Security.Principal.WindowsIdentity.GetCurrent().Name offers exactly
what I wanted, so while the UserDomainName problem persist, I can leave it
as a report to the Framework development team.
 
Did you runas using /env ?

Willy.

Lau Lei Cheong said:
No. I'm currently connected to the domain, and I'm sure the connection to
Domain Controller is Ok (This is obvious, I can't use runas to run
something as Domain Administrator if I can't anthenicate against the
domain server. As I won't normally logon my desktop with that identity, my
desktop can't possibly have cached the password).

Anyway, I've find the
System.Security.Principal.WindowsIdentity.GetCurrent().Name offers exactly
what I wanted, so while the UserDomainName problem persist, I can leave it
as a report to the Framework development team.
 
Back
Top