Retrieving User Name

  • Thread starter Thread starter Simon Jefferies
  • Start date Start date
S

Simon Jefferies

Hello,

How do I get the user name (information) for the currently logged in user
using VB. NET?

TIA
Simon Jefferies
Tools Programmer
Headfirst Productions
 
Hi,

Trace.WriteLine(Environment.UserName)

Trace.WriteLine(SystemInformation.UserName)



Ken
 
Thanks,

Whats the difference between Environment.UserName and
SystemInformation.UserName?

Regards
Simon Jefferies
Tools Programmer
Headfirst Productions
 
Check out the docs for info on Security and specifically Permissions.

Some code could go: (After importing the System.Security.Permissions
namespace)

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)

Dim wp as WindowsPricipal
wp = Ctype(Threading.Thread.CurrentPrinciapl, WindowsPrincipal)

Dim id as WindowsIdentity
id = Ctype(wp.Identity, WindowsIdentity)

Debug.Writeline(id.Name)


*And then use the intellisense or the docs to find the info available
about the identity - theres quite a lot of useful info as you would
expect)
If you then need to ensure a user has specific permissions/authority
to perform a function in your app, and those permissions are based on
Windows security, then you should check out securty checks, like
Demand.

Hth
Richard
 
Back
Top