Reading the Login UserID from XP

G

Guest

Hej

I want to read the current Login at XP user Login to my C# Windows program.
I know how to use Namespace Microsoft.win32 and registryKey and Registry
class but I got a string i REG_SZ format not in normal Uni16 format by use
this little picse of code.

RegistryKey user = Registry.CurrentUser;

RegistryKey userid = user.OpenSubKey("Identities");


string UserIDStr = (string ) userid.GetValue("Last User ID");

user.Close();

So how to read the PC user Login in my proram so the user don't have to
write he/hers User ID again then they use the programmet beause I have to
store the users ID in a file

Best regard
Kim S.
 
A

Alberto Poblacion

Kim said:
I want to read the current Login at XP user Login to my C# Windows
program.
I know how to use Namespace Microsoft.win32 and registryKey and Registry
class but I got a string i REG_SZ format not in normal Uni16 format by use
this little picse of code.

RegistryKey user = Registry.CurrentUser;

RegistryKey userid = user.OpenSubKey("Identities");


string UserIDStr = (string ) userid.GetValue("Last User
ID");

user.Close();

So how to read the PC user Login in my proram so the user don't have to
write he/hers User ID again then they use the programmet beause I have to
store the users ID in a file

Instead of going to the Registry, you could use
WindowsIdentity.GetCurrent():

using System.Security.Principal;
....
string UserIDStr = WindowsIdentity.GetCurrent().Name;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top