WindowsIdentity.WindowsIdentity(IntPtr, String, WindowsAccountType, Boolean) Constructor

Initializes a new instance of the WindowsIdentity class for the user represented by the specified Windows account token, the specified authentication type, the specified Windows account type, and the specified authentication status.

Namespace: System.Security.Principal
Assembly: mscorlib (in mscorlib.dll)

public:
WindowsIdentity (
	IntPtr userToken, 
	String^ type, 
	WindowsAccountType acctType, 
	bool isAuthenticated
)
public WindowsIdentity (
	IntPtr userToken, 
	String type, 
	WindowsAccountType acctType, 
	boolean isAuthenticated
)
public function WindowsIdentity (
	userToken : IntPtr, 
	type : String, 
	acctType : WindowsAccountType, 
	isAuthenticated : boolean
)
Not applicable.

Parameters

userToken

The account token for the user on whose behalf the code is running.

type

The type of authentication used to identify the user.

acctType

One of the WindowsAccountType values.

isAuthenticated

true to indicate that the user is authenticated; otherwise, false.

Exception typeCondition

ArgumentException

userToken is 0.

-or-

userToken is duplicated and invalid for impersonation.

SecurityException

The caller does not have the correct permissions.

-or-

A Win32 error occurred.

You can retrieve the token represented by userToken by calling unmanaged code such as the Win32 API LogonUser function. Always release userToken by calling the Win32 API Close function. For more information on calling unmanaged code, see Consuming Unmanaged DLL Functions.

The following code shows the use of the WindowsIdentity constructor to create a new instance of the WindowsIdentity class for the user represented by the specified Windows account token, the specified authentication type, the specified Windows account type, and the specified authentication status. This code example is part of a larger example provided for the WindowsIdentity class.

String^ authenticationType = "WindowsAuthentication";
WindowsAccountType guestAccount = WindowsAccountType::Guest;
bool isAuthenticated = true;
WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken,authenticationType,guestAccount,isAuthenticated );


String authenticationType = "WindowsAuthentication";
WindowsAccountType guestAccount = WindowsAccountType.Guest;
boolean isAuthenticated = true;
WindowsIdentity windowsIdentity = new WindowsIdentity(logonToken,
    authenticationType, guestAccount, isAuthenticated);

Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show: