Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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);
}
}
}
// 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;
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);
}
}
}
// 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
- SafeNativeMethods.cs
- StylusEventArgs.cs
- ValidationEventArgs.cs
- TextDecorationCollection.cs
- Connector.xaml.cs
- StreamProxy.cs
- ArrayItemReference.cs
- OracleConnectionStringBuilder.cs
- WmpBitmapEncoder.cs
- FillRuleValidation.cs
- FontStretch.cs
- Rotation3DAnimation.cs
- SqlDataSourceCommandEventArgs.cs
- StorageAssociationTypeMapping.cs
- StringPropertyBuilder.cs
- ScrollBar.cs
- BasicHttpMessageCredentialType.cs
- WSHttpBindingBase.cs
- hwndwrapper.cs
- ResizingMessageFilter.cs
- Win32Exception.cs
- PolicyStatement.cs
- DataGridHeadersVisibilityToVisibilityConverter.cs
- LexicalChunk.cs
- EditorZoneDesigner.cs
- GeometryGroup.cs
- SourceInterpreter.cs
- Base64Decoder.cs
- PolyQuadraticBezierSegment.cs
- RtfToken.cs
- SecurityElementBase.cs
- GrammarBuilderBase.cs
- MemoryFailPoint.cs
- WebControlAdapter.cs
- DataServiceCollectionOfT.cs
- MenuItemAutomationPeer.cs
- MenuItem.cs
- SqlAliaser.cs
- NavigationCommands.cs
- PermissionRequestEvidence.cs
- DockingAttribute.cs
- RuntimeComponentFilter.cs
- PropertyManager.cs
- SqlRecordBuffer.cs
- DefaultValueMapping.cs
- RadioButtonList.cs
- DataException.cs
- RMEnrollmentPage1.cs
- ReadOnlyDataSource.cs
- BindStream.cs
- UTF32Encoding.cs
- Encoding.cs
- ShutDownListener.cs
- PolicyManager.cs
- EdmConstants.cs
- SqlCacheDependencyDatabaseCollection.cs
- ProviderUtil.cs
- SerializationInfo.cs
- ValueTable.cs
- DescendantBaseQuery.cs
- SqlDataSource.cs
- ErrorsHelper.cs
- FormatPage.cs
- ValidationPropertyAttribute.cs
- DirectionalLight.cs
- PingOptions.cs
- processwaithandle.cs
- TrustLevelCollection.cs
- ItemCheckedEvent.cs
- XmlWriterSettings.cs
- AstTree.cs
- TriggerBase.cs
- RuleSettings.cs
- TabletCollection.cs
- CoTaskMemSafeHandle.cs
- UserControlParser.cs
- ListViewInsertEventArgs.cs
- OleDragDropHandler.cs
- AsyncCodeActivity.cs
- ExpressionVisitor.cs
- FacetEnabledSchemaElement.cs
- DEREncoding.cs
- StatusStrip.cs
- RemotingException.cs
- VirtualizingStackPanel.cs
- Int32Storage.cs
- UnsafeNativeMethods.cs
- RealizationDrawingContextWalker.cs
- _ListenerResponseStream.cs
- PropertyPathWorker.cs
- IssuedTokenServiceCredential.cs
- PixelFormatConverter.cs
- TransactionManager.cs
- WinFormsUtils.cs
- XmlUnspecifiedAttribute.cs
- RectValueSerializer.cs
- ImageButton.cs
- EmptyQuery.cs
- ListDictionary.cs
- SoapAttributes.cs