Skip to Content
Hidden WPF: Secrets for Creating Great Applications in Windows Presentation Foundation
book

Hidden WPF: Secrets for Creating Great Applications in Windows Presentation Foundation

by Alessandro Del Sole
February 2013
Beginner to intermediate
68 pages
1h 50m
English
Sams
Content preview from Hidden WPF: Secrets for Creating Great Applications in Windows Presentation Foundation

Visual Basic: Initializing My.User

If you write programs in Visual Basic and use the My namespace, you know that the User object allows accessing properties of the user who logged into the operating system. However, in Windows Forms the following line returns the username in the form of domain\username and works correctly:

Dim userName As String = My.User.Name

In WPF, the same line returns an empty string. There are two ways of solving this problem. The first way is by initializing My.User as follows:

My.User.InitializeWithWindowsUser()Dim userName As String = My.User.Name

The second way is by using security and identity objects directly, as in the following code:

Dim userName As String = System.Security.Principal.WindowsIdentity.GetCurrent().Name ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro WPF in C# 2010: Windows Presentation Foundation in .NET 4

Pro WPF in C# 2010: Windows Presentation Foundation in .NET 4

Matthew MacDonald
WPF in Action with Visual Studio 2008

WPF in Action with Visual Studio 2008

Arlen Feldman, Maxx Daymon

Publisher Resources

ISBN: 9780133432473