Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / CompMod / Microsoft / Win32 / SafeHandles / SafeProcessHandle.cs / 1 / SafeProcessHandle.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: SafeProcessHandle ** ** A wrapper for a process handle ** ** ===========================================================*/ using System; using System.Security; using System.Diagnostics; 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 SafeProcessHandle : SafeHandleZeroOrMinusOneIsInvalid { internal static SafeProcessHandle InvalidHandle = new SafeProcessHandle(IntPtr.Zero); // Note that OpenProcess returns 0 on failure internal SafeProcessHandle() : base(true) {} [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] internal SafeProcessHandle(IntPtr handle) : base (true) { SetHandle(handle); } // Not currently called //[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] //internal SafeProcessHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) { // SetHandle(existingHandle); //} [DllImport(ExternDll.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)] internal static extern SafeProcessHandle OpenProcess(int access, bool inherit, int processId); internal void InitialSetHandle(IntPtr h){ Debug.Assert(base.IsInvalid, "Safe handle should only be set once"); base.handle = h; } override protected bool ReleaseHandle() { return SafeNativeMethods.CloseHandle(handle); } } }
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataGridRowEventArgs.cs
- XmlNodeChangedEventArgs.cs
- CodeAssignStatement.cs
- LayoutDump.cs
- SigningCredentials.cs
- WorkflowDebuggerSteppingAttribute.cs
- StoreItemCollection.Loader.cs
- RankException.cs
- OracleCommand.cs
- WriteFileContext.cs
- DateTimeOffset.cs
- QuaternionKeyFrameCollection.cs
- XmlEntityReference.cs
- CallSiteOps.cs
- DefaultSerializationProviderAttribute.cs
- WebDescriptionAttribute.cs
- KoreanCalendar.cs
- ContextMenu.cs
- StoreItemCollection.cs
- HtmlTextArea.cs
- PropertyInformationCollection.cs
- NativeCompoundFileAPIs.cs
- CalloutQueueItem.cs
- RegexTypeEditor.cs
- TableLayoutPanelCellPosition.cs
- SlotInfo.cs
- KeyProperty.cs
- AssociatedControlConverter.cs
- SecurityHelper.cs
- WebPartHelpVerb.cs
- designeractionlistschangedeventargs.cs
- DefaultValueConverter.cs
- BuildProvider.cs
- SpecialNameAttribute.cs
- Pen.cs
- SqlStatistics.cs
- DbConnectionPoolGroupProviderInfo.cs
- XmlSchemaResource.cs
- CodeGen.cs
- SharedPerformanceCounter.cs
- X509InitiatorCertificateClientElement.cs
- CookielessHelper.cs
- XmlSchemaImport.cs
- FormsAuthenticationTicket.cs
- PropertyCollection.cs
- SqlNamer.cs
- DataListItemCollection.cs
- OletxCommittableTransaction.cs
- SecurityManager.cs
- HtmlInputControl.cs
- ErrorTableItemStyle.cs
- XmlSerializer.cs
- ErrorTableItemStyle.cs
- ToolStripActionList.cs
- Size3D.cs
- MediaTimeline.cs
- DrawToolTipEventArgs.cs
- MultiPageTextView.cs
- followingsibling.cs
- Select.cs
- MediaElement.cs
- LoaderAllocator.cs
- XsdDataContractExporter.cs
- ConnectionManagementElementCollection.cs
- ContentHostHelper.cs
- TranslateTransform.cs
- ItemContainerGenerator.cs
- ProcessModuleDesigner.cs
- BooleanStorage.cs
- ResXBuildProvider.cs
- CollectionsUtil.cs
- FormatConvertedBitmap.cs
- TextTreeTextElementNode.cs
- ClickablePoint.cs
- ColorDialog.cs
- Select.cs
- VBIdentifierDesigner.xaml.cs
- BroadcastEventHelper.cs
- FileReservationCollection.cs
- _ContextAwareResult.cs
- PropertyGeneratedEventArgs.cs
- ScriptingWebServicesSectionGroup.cs
- PropertyTabChangedEvent.cs
- MulticastDelegate.cs
- InfoCardArgumentException.cs
- ModelPerspective.cs
- DataGridRow.cs
- WpfSharedXamlSchemaContext.cs
- ConvertersCollection.cs
- PropertyValueUIItem.cs
- CursorConverter.cs
- ObjectAnimationUsingKeyFrames.cs
- StickyNoteHelper.cs
- DataServiceProcessingPipelineEventArgs.cs
- ConditionedDesigner.cs
- MailAddress.cs
- XmlException.cs
- OleDbParameterCollection.cs
- WindowVisualStateTracker.cs
- ToolStripManager.cs