Re: How to retrieve user's domain correctly?

From: WNC (wcedeno_at_online.nospam)
Date: 09/17/04


Date: Fri, 17 Sep 2004 05:59:06 -0700

Thank you Drebin for your response.

We have checked this multiple times and we are certain that we have
logged-in through the domain (USERX_DOMAIN). We used another system which
does not have the local USERX account and we get the correct information.

We investigated further this bug and found that even a WIN32 API returns the
incorrect information. Following is the summary of what we have seen so far.
All of the results were obtained from a system running .Net framework 1.1 on
Windows 2000 profesional SP4.

1. .Net System.Environment.UserDomainName -> Incorrectly returns MACHINE_NAME.
2. .Net SystemInformation.UserDomainName -> Incorrectly returns MACHINE_NAME.
3. Win32 API LookupAccountName -> Incorrectly returns MACHINE_NAME.
4. .Net System.Environment.GetEnvironmentVariable("USERDOMAIN") -> Correctly
returns USERX_DOMAIN.
5. Win32 API GetUserNameEx with NAME_FORMAT set to -> Correctly returns
USERX_DOMAIN/USERX.

  At this moment it looks that the problem is being propagated to the .Net
framework classes by the Win32 API.
WNC

"Drebin" wrote:

> It sounds like you authenticated through your local machine - in other
> words, when you go to login, you specify to log in from the local machine
> instead of the domain.
>
> If that is the case, this is correct - you ARE logged in as your machine
> account and NOT your domain account. And if you are trying to get the
> running user of the CURRENT process, this is pretty reliable:
>
> string strUser = Environment.UserDomainName + "\\" + Environment.UserName;
>
> HTH
>
>
> "WNC" <wcedeno@online.nospam> wrote in message
> news:0DAE4440-A1C9-4BF8-8EC9-D91E0869FE9C@microsoft.com...
> > If you are using any of the following two calls below, you may not get
> > what
> > you are looking for.
> >
> > string domain = System.Environment.UserDomainName;
> > string domain = SystemInformation.UserDomainName;
> >
> > I happen to have an account USERX as part of the local domain
> > (MACHINE_NAME)
> > of my system. The same account name USERX is used for my USERX_DOMAIN
> > domain.
> > I logged in as USERX_DOMAIN\USERX but the domain returned by those two
> > calls
> > is MACHINE_NAME.
> >
> > As a workaround, I am going to use the value of the environment variable
> > USERDOMAIN, which is correct, to get the correct domain name. How could I
> > obtain the correct domain name without depending on an overwritable
> > environment variable?
> >
> > --
> > WNC
>
>
>



Relevant Pages

  • Re: User Accounts
    ... prevent someone from creating their own user account when I am logged on as ... wanted to do will happen during Fred's logged-in session... ... and thus must retain its settings. ... What is more, I refuse to even read, let alone reply to, posts of this kind. ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Need help recovering EFS encryped files
    ... the password of the logged-in account. ... Reset always breaks access to EFS files for the account whose ...
    (microsoft.public.windowsxp.security_admin)
  • Re: installing SMS 2003 on Windows 2003 Server
    ... sql account specified during setup must be working ok. ... Highlight the Security Rights node to see what rights your currently ... logged-in account has. ... The installation completes without error. ...
    (microsoft.public.sms.setup)
  • Re: Connection Failed - SMS Admin Console
    ... the box is logged in woth the domain Administrator ... >It connects using your logged-in account. ... >> errors relating to unsuccesful login to the SQL Server ...
    (microsoft.public.sms.admin)
  • Re: How to retrieve users domain correctly?
    ... If you DO have a matching account on your local machine, ... > framework classes by the Win32 API. ...
    (microsoft.public.dotnet.framework)