Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / Microsoft / Win32 / SafeHandles / SafeProcessHandle.cs / 1305376 / 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; using System.Runtime.Versioning; namespace Microsoft.Win32.SafeHandles { [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) {} 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)] [ResourceExposure(ResourceScope.Machine)] 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); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // 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; using System.Runtime.Versioning; namespace Microsoft.Win32.SafeHandles { [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) {} 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)] [ResourceExposure(ResourceScope.Machine)] 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); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SQLBytes.cs
- TimeZone.cs
- Ticks.cs
- CuspData.cs
- DataGridViewComboBoxCell.cs
- SubstitutionDesigner.cs
- IssuedTokenClientElement.cs
- Interlocked.cs
- XPathSingletonIterator.cs
- SrgsText.cs
- SafeUserTokenHandle.cs
- CheckBoxAutomationPeer.cs
- DocumentPageTextView.cs
- TableCellCollection.cs
- MonthChangedEventArgs.cs
- ClosableStream.cs
- CodeNamespaceCollection.cs
- COM2Properties.cs
- ScrollEventArgs.cs
- ObjectStateEntryOriginalDbUpdatableDataRecord.cs
- XmlTextReader.cs
- ExpressionVisitorHelpers.cs
- XmlSortKeyAccumulator.cs
- HMACSHA512.cs
- EventLogHandle.cs
- QuaternionAnimation.cs
- TreeViewItem.cs
- Bitmap.cs
- GroupPartitionExpr.cs
- WebChannelFactory.cs
- ColorAnimation.cs
- CroppedBitmap.cs
- Panel.cs
- ClientProxyGenerator.cs
- webeventbuffer.cs
- FixedSOMTableCell.cs
- TextServicesDisplayAttribute.cs
- ChannelRequirements.cs
- RelationshipType.cs
- IDataContractSurrogate.cs
- WorkflowTimerService.cs
- SByteConverter.cs
- BuildProvider.cs
- VolatileResourceManager.cs
- SqlDataSourceStatusEventArgs.cs
- MobileUITypeEditor.cs
- WeakReadOnlyCollection.cs
- CodeCommentStatementCollection.cs
- DataSetSchema.cs
- XNameTypeConverter.cs
- XmlChildNodes.cs
- UnmanagedMemoryStreamWrapper.cs
- StateItem.cs
- EntitySqlQueryCacheKey.cs
- SchemaImporterExtensionElementCollection.cs
- InputReport.cs
- IERequestCache.cs
- WebServiceEnumData.cs
- CharacterMetricsDictionary.cs
- UITypeEditor.cs
- GradientSpreadMethodValidation.cs
- XhtmlConformanceSection.cs
- QueryContinueDragEventArgs.cs
- LayoutExceptionEventArgs.cs
- TreeSet.cs
- NetworkCredential.cs
- BinaryMethodMessage.cs
- CodeParameterDeclarationExpressionCollection.cs
- ScrollProperties.cs
- XpsFixedDocumentSequenceReaderWriter.cs
- filewebrequest.cs
- Path.cs
- SctClaimDictionary.cs
- ProtocolsConfiguration.cs
- ServiceHttpHandlerFactory.cs
- MILUtilities.cs
- AstNode.cs
- WindowShowOrOpenTracker.cs
- CodeMemberField.cs
- HtmlElement.cs
- ToolStripDropDownClosedEventArgs.cs
- BamlResourceDeserializer.cs
- ProxyWebPartManager.cs
- GridViewCommandEventArgs.cs
- WaitHandle.cs
- StorageTypeMapping.cs
- unsafeIndexingFilterStream.cs
- SystemFonts.cs
- EntityDataSourceEntitySetNameItem.cs
- ErrorTableItemStyle.cs
- CatalogPartDesigner.cs
- TypeValidationEventArgs.cs
- CompileLiteralTextParser.cs
- PeerTransportCredentialType.cs
- RegexTree.cs
- CacheOutputQuery.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- BamlRecordHelper.cs
- Renderer.cs
- GeometryConverter.cs