Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / CompMod / Microsoft / Win32 / SafeHandles / SafeUserTokenHandle.cs / 1 / SafeUserTokenHandle.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SafeUserTokenHandle
**
** Author: David Gutierrez ([....])
**
** A wrapper for a user token handle
**
** Date: July 8, 2002
**
===========================================================*/
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
namespace Microsoft.Win32.SafeHandles {
[HostProtectionAttribute(MayLeakOnAbort = true)]
[SuppressUnmanagedCodeSecurityAttribute]
internal sealed class SafeUserTokenHandle : SafeHandleZeroOrMinusOneIsInvalid
{
// Note that OpenProcess returns 0 on failure.
internal SafeUserTokenHandle() : base (true) {}
internal SafeUserTokenHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) {
SetHandle(existingHandle);
}
#if !FEATURE_PAL
[DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true, BestFitMapping=false)]
internal extern static bool DuplicateTokenEx(SafeHandle hToken, int access, NativeMethods.SECURITY_ATTRIBUTES tokenAttributes, int impersonationLevel, int tokenType, out SafeUserTokenHandle hNewToken);
#endif // !FEATURE_PAL
[DllImport(ExternDll.Kernel32, ExactSpelling=true, SetLastError=true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
private static extern bool CloseHandle(IntPtr handle);
override protected bool ReleaseHandle()
{
return CloseHandle(handle);
}
}
}
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Deflater.cs
- RevocationPoint.cs
- PublisherMembershipCondition.cs
- DetailsViewInsertedEventArgs.cs
- _WebProxyDataBuilder.cs
- PropertyFilterAttribute.cs
- RijndaelManaged.cs
- AssemblySettingAttributes.cs
- CustomExpressionEventArgs.cs
- CodeAttributeDeclarationCollection.cs
- Visual.cs
- ProfessionalColorTable.cs
- TransactionContextManager.cs
- MultiAsyncResult.cs
- Soap12ProtocolImporter.cs
- DuplexChannel.cs
- Transform.cs
- XslNumber.cs
- QueryConverter.cs
- PropertyConverter.cs
- TextParaClient.cs
- RequiredAttributeAttribute.cs
- ContentPosition.cs
- QuotedPrintableStream.cs
- iisPickupDirectory.cs
- TableCellCollection.cs
- SafeFindHandle.cs
- RoutedEventConverter.cs
- DeclaredTypeElement.cs
- DataSvcMapFile.cs
- X509Utils.cs
- InterleavedZipPartStream.cs
- DataGridViewSelectedRowCollection.cs
- Transform.cs
- VectorCollection.cs
- LayoutEvent.cs
- TextProperties.cs
- ApplicationSecurityInfo.cs
- DynamicRouteExpression.cs
- SQLDecimal.cs
- SqlDataSourceFilteringEventArgs.cs
- Operand.cs
- VectorAnimationUsingKeyFrames.cs
- Common.cs
- WindowsGraphicsCacheManager.cs
- WebEventCodes.cs
- DataServiceQueryProvider.cs
- PerformanceCounterPermissionEntryCollection.cs
- PackWebRequestFactory.cs
- SHA512Cng.cs
- ModulesEntry.cs
- SafeFileMappingHandle.cs
- ItemCheckEvent.cs
- InvalidWMPVersionException.cs
- ObjectView.cs
- GeometryGroup.cs
- ObjectDataSourceFilteringEventArgs.cs
- OrderPreservingMergeHelper.cs
- DoubleLinkListEnumerator.cs
- ProtocolsSection.cs
- ContextInformation.cs
- SqlInfoMessageEvent.cs
- UseLicense.cs
- CompiledIdentityConstraint.cs
- embossbitmapeffect.cs
- Baml2006Reader.cs
- DragCompletedEventArgs.cs
- AuthorizationRule.cs
- BatchStream.cs
- BufferModeSettings.cs
- _AuthenticationState.cs
- HtmlElementCollection.cs
- BuilderPropertyEntry.cs
- WindowsStreamSecurityBindingElement.cs
- PlaceHolder.cs
- Rule.cs
- CompilerParameters.cs
- PageThemeParser.cs
- DataGridViewRowsRemovedEventArgs.cs
- SqlServer2KCompatibilityAnnotation.cs
- ErrorFormatter.cs
- _Connection.cs
- AuthorizationRuleCollection.cs
- SQLBoolean.cs
- CategoryAttribute.cs
- ActivationProxy.cs
- QueryOutputWriter.cs
- DescriptionAttribute.cs
- SQLString.cs
- PropertyGroupDescription.cs
- InputMethodStateTypeInfo.cs
- DataRowExtensions.cs
- MenuItem.cs
- SmiRequestExecutor.cs
- CustomBinding.cs
- ToolStripScrollButton.cs
- PropertyReferenceExtension.cs
- GAC.cs
- RangeValidator.cs
- StronglyTypedResourceBuilder.cs