本文整理汇总了C#中Microsoft.Win32.SafeHandles.SafeProcessHandle类的典型用法代码示例。如果您正苦于以下问题:C# SafeProcessHandle类的具体用法?C# SafeProcessHandle怎么用?C# SafeProcessHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SafeProcessHandle类属于Microsoft.Win32.SafeHandles命名空间,在下文中一共展示了SafeProcessHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddProcess
public void AddProcess(SafeProcessHandle processHandle)
{
ValidateDisposed();
if (!AssignProcessToJobObject(_handle, processHandle))
{
throw new InvalidOperationException("Unable to add the process");
}
}
示例2: DuplicateHandle
internal static extern bool DuplicateHandle(
SafeProcessHandle hSourceProcessHandle,
SafeHandle hSourceHandle,
SafeProcessHandle hTargetProcess,
out SafeWaitHandle targetHandle,
int dwDesiredAccess,
bool bInheritHandle,
int dwOptions
);
示例3: DuplicateHandle
SafeProcessHandle DuplicateHandle(SafeProcessHandle process, IntPtr handle, bool throwOnFail = true)
{
SafeProcessHandle dupHandle;
if (!Win32.DuplicateHandle(process, handle, Win32.GetCurrentProcess(), out dupHandle, 0, false, Win32.DUPLICATE_SAME_ACCESS))
if (throwOnFail)
throw new Win32Exception();
else
return null;
return dupHandle;
}
示例4: GetExitCodeProcess
public static bool GetExitCodeProcess (SafeProcessHandle processHandle, out int exitCode)
{
bool release = false;
try {
processHandle.DangerousAddRef (ref release);
return GetExitCodeProcess (processHandle.DangerousGetHandle (), out exitCode);
} finally {
if (release)
processHandle.DangerousRelease ();
}
}
示例5: Protect
public Protect(SafeProcessHandle handle, VirtualQueryInfo info, int protect)
{
this.handle = handle;
this.info = info;
this.protect = protect;
if (protect == info.Protect)
return;
int oldProtect;
if (!Win32.VirtualProtectEx(handle.DangerousGetHandle(), (IntPtr)info.StartAddress, (IntPtr)info.RegionSize, protect, out oldProtect))
throw new Win32Exception();
}
示例6: DuplicateHandle
public static bool DuplicateHandle(HandleRef hSourceProcessHandle, HandleRef hSourceHandle, HandleRef hTargetProcess,
out SafeProcessHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
{
MonoIOError error;
IntPtr nakedTargetHandle;
bool ret = MonoIO.DuplicateHandle (hSourceProcessHandle.Handle, hSourceHandle.Handle, hTargetProcess.Handle,
out nakedTargetHandle, dwDesiredAccess, bInheritHandle ? 1 : 0, dwOptions, out error);
if (error != MonoIOError.ERROR_SUCCESS)
throw MonoIO.GetException (error);
targetHandle = new SafeProcessHandle (nakedTargetHandle, true);
return ret;
}
示例7: ProcessWaitHandle
internal ProcessWaitHandle( SafeProcessHandle processHandle): base() {
SafeWaitHandle waitHandle = null;
bool succeeded = NativeMethods.DuplicateHandle(
new HandleRef(this, NativeMethods.GetCurrentProcess()),
processHandle,
new HandleRef(this, NativeMethods.GetCurrentProcess()),
out waitHandle,
0,
false,
NativeMethods.DUPLICATE_SAME_ACCESS);
if (!succeeded) {
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
}
this.SafeWaitHandle = waitHandle;
}
示例8: ProcessWaitHandle
internal ProcessWaitHandle(SafeProcessHandle processHandle)
{
// Get the process ID from the process handle. The handle is just a facade that wraps
// the process ID, and closing the handle won't affect the process or its ID at all.
// So we can grab it, and it's not "dangerous".
int processId = (int)processHandle.DangerousGetHandle();
// Create a wait state holder for this process ID. This gives us access to the shared
// wait state associated with this process.
_waitStateHolder = new ProcessWaitState.Holder(processId);
// Get the wait state's event, and use that event's safe wait handle
// in place of ours. This will let code register for completion notifications
// on this ProcessWaitHandle and be notified when the wait state's handle completes.
ManualResetEvent mre = _waitStateHolder._state.EnsureExitedEvent();
this.SetSafeWaitHandle(mre.GetSafeWaitHandle());
}
示例9: ProcessWaitHandle
internal ProcessWaitHandle(SafeProcessHandle processHandle)
{
SafeWaitHandle waitHandle = null;
SafeProcessHandle currentProcHandle = Interop.mincore.GetCurrentProcess();
bool succeeded = Interop.mincore.DuplicateHandle(
currentProcHandle,
processHandle,
currentProcHandle,
out waitHandle,
0,
false,
Interop.DUPLICATE_SAME_ACCESS);
if (!succeeded)
{
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
}
this.SetSafeWaitHandle(waitHandle);
}
示例10: ProcessWaitHandle
internal ProcessWaitHandle( SafeProcessHandle processHandle): base() {
SafeWaitHandle waitHandle = null;
bool succeeded = NativeMethods.DuplicateHandle(
new HandleRef(this, NativeMethods.GetCurrentProcess()),
processHandle,
new HandleRef(this, NativeMethods.GetCurrentProcess()),
out waitHandle,
0,
false,
NativeMethods.DUPLICATE_SAME_ACCESS);
if (!succeeded) {
#if MONO
// In Mono, Marshal.GetHRForLastWin32Error is not implemented;
// and also DuplicateHandle throws its own exception rather
// than returning false on error, so this code is unreachable.
throw new SystemException("Unknown error in DuplicateHandle");
#else
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
#endif
}
this.SafeWaitHandle = waitHandle;
}
示例11: GetProcessIdFromHandle
public static int GetProcessIdFromHandle(SafeProcessHandle processHandle) {
if (IsNt)
return NtProcessManager.GetProcessIdFromHandle(processHandle);
else
throw new PlatformNotSupportedException(SR.GetString(SR.WinNTRequired));
}
示例12: GetProcessPriorityBoost
internal static extern bool GetProcessPriorityBoost(SafeProcessHandle handle, out bool disabled);
示例13: SetPriorityClass
public static bool SetPriorityClass(SafeProcessHandle handle, int priorityClass)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return SetPriorityClass (handle.DangerousGetHandle (), priorityClass);
} finally {
if (release)
handle.DangerousRelease ();
}
}
示例14: GetProcessTimes
public static bool GetProcessTimes (SafeProcessHandle handle, out long creation, out long exit, out long kernel, out long user)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return GetProcessTimes (handle.DangerousGetHandle (), out creation, out exit, out kernel, out user);
} finally {
if (release)
handle.DangerousRelease ();
}
}
示例15: SetProcessWorkingSetSize
public static bool SetProcessWorkingSetSize (SafeProcessHandle handle, IntPtr min, IntPtr max)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return SetProcessWorkingSetSize (handle.DangerousGetHandle (), min, max);
} finally {
if (release)
handle.DangerousRelease ();
}
}