Why does the .NET report the old name of the account??

  • Thread starter Thread starter Petrus Crassus
  • Start date Start date
P

Petrus Crassus

A month ago I had to re-install Win XP (Home version). I did not give my
name to the installing program, so it created a default account called
"Owner" with administrator privileges.

Later I changed the account name to correspond my real name. Now it is
shown correctly both in the start menu and in the login screen.

But I still get the old name ("Owner") if I call any of these:

- SystemInformation.UserName
- System.Security.Principal.WindowsIdentity.GetCurrent().Name
- System.Environment.UserName

How do you fix this?
 
When an Windows Account is first setup, it is given a 'Name', which
can't be changed.

When you 'change' the user name for the Welcome Screen and Start Menu,
windows updates the users 'Real Name' (I think it's called), and uses
this.

The WindowsIdentity class doesn't seem to have the Real Name though :(

I've had a quick look, but can't find anything else that might return
it, but it has to be possible if Windows can do it.
 
raican said:
I've had a quick look, but can't find anything else that might return
it, but it has to be possible if Windows can do it.

Yep. That seems plausible. If you (or somebody else) find it, please
tell me!

I think this makes the user identification in some cases somewhat
untrustworthy.
 
Slight mistake... It's called Fullname, not Real Name. Sorry, my bad.

Have a look at 'Win32_UserAccount' on the MSDN (msdn.microsoft.com) it
has the Fullname. How to get at it, i'm not sure yet. I'll have a look
when i get home (at work atm (shhh, don't tell)), and i'll post any
code i come up with. :)

hope this helps
 
Well, here goes nothing...

// Copy From Here...
using System;
using System.Management;

class User
{
[STAThread]
static void Main(string[] args)
{
SelectQuery q = new SelectQuery();

q.ClassName = "Win32_UserAccount";
q.Condition = "Name = \"" + System.Environment.UserName + "\"";

Console.WriteLine(q.QueryString);

ManagementObjectSearcher s = new ManagementObjectSearcher(q);
foreach(ManagementObject o in s.Get())
Console.WriteLine("Full Username - {0}", o["FullName"]);

Console.ReadLine();
}
}
// ... To Here.

This worked for me, hope it helps
 
Back
Top