Click here to Skip to main content
15,905,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have tried everything for the last two weeks and can't solve the following problem:
VB
Dim LogonUserFName As String = UserPrincipal.Current.GivenName
Dim LogonUserSName As String = UserPrincipal.Current.Surname
Dim LogonUserID As String = UserPrincipal.Current.SamAccountName

MsgBox(LogonUserFName & " " & LogonUserSName & " " & LogonUserID)


The issue is that this calls the active directory for the information. I'm using a tablet to do some inspecting off site and I need to know who is logged into the tablet. The error I'm getting is that the server could not be contacted.

I know that this information is also stored locally somewhere in windows because it shows my first name and last name on the start menu when I'm logged in offline.

I have also tried:
VB
Dim UserName As String = My.User.Name
MsgBox(UserName)

and
VB
Dim UserName As String = Environment.UserName
MsgBox(UserName)

aswell as
VB
Dim usernameID As String = System.Security.Principal.WindowsIdentity.GetCurrent.Name
MsgBox(UserName)


The problem with all the methods above is that they only return the "User Login Name" which in my case is a 8 Digit number.

Any help, ideas or suggestions would be greatly appreciated!
Posted

1 solution

What you're seeing is the cached credentials. In the event there is no domain controller available, you can still login to Windows using the cached account.

The data you're looking for can be had from the Registry, but you need to implement a little searching to get it. Look under the key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\

In there, you'll find a set of keys with SID's for names. Search each folder for a value called "Distiguished-Name" (I think - from memory!) You'll get back an ADS path that you'll have to parse up to get the name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900