My.User.InitializeWithWindowsUser Method

Sets the thread's current principal to the Windows user that started the application.

' Usage
My.User.InitializeWithWindowsUser()
' Declaration
Public Sub InitializeWithWindowsUser()

You can use the My.User.InitializeWithWindowsUser method to set the thread's current principal to the Windows user that started the application. The Visual Basic Application Model in a Windows application calls this method at startup by default. In other project types, you must set the thread's current principal by calling this method explicitly or by assigning a value to Thread.CurrentPrincipal.

In Windows projects, the My.User object is based on the thread's current principal; therefore, this method can change the information My.User returns. In an ASP.NET application, the My.User object is based on the current HTTP request's user identity, and is unaffected by this method.

NoteNote:

The exact behavior of the My.User object depends on the type of application and on the operating system on which the application runs. For more information, see My.User Object.

This is an advanced member; it does not show in IntelliSense unless you click the All tab.

Namespace: Microsoft.VisualBasic.ApplicationServices

Class: User, WebUser

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type

Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

Yes

Windows Service

Yes

Web Site

Yes

The following permission may be necessary:

Permission

Description

SecurityPermission

Describes a set of security permissions applied to code. Associated enumeration: ControlPrincipal.

For more information, see Code Access Security and Requesting Permissions.

Community Additions

ADD
Show: