mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
2106d2a2e6
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@1233 21ef857c-d57f-4fe0-8362-d861dc6d29cd
50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using ProcessHacker.Native.Api;
|
|
using ProcessHacker.Native.Security;
|
|
|
|
namespace ProcessHacker.Native.Objects
|
|
{
|
|
public class DesktopHandle : Win32Handle<DesktopAccess>
|
|
{
|
|
public static DesktopHandle GetCurrent()
|
|
{
|
|
return GetThreadDesktop(Win32.GetCurrentThreadId());
|
|
}
|
|
|
|
public static DesktopHandle GetThreadDesktop(int threadId)
|
|
{
|
|
IntPtr handle = Win32.GetThreadDesktop(threadId);
|
|
|
|
if (handle == IntPtr.Zero)
|
|
Win32.ThrowLastError();
|
|
|
|
return new DesktopHandle(handle, false);
|
|
}
|
|
|
|
public DesktopHandle(string name, bool allowOtherAccountHook, DesktopAccess access)
|
|
{
|
|
this.Handle = Win32.OpenDesktop(name, allowOtherAccountHook ? 1 : 0, false, access);
|
|
|
|
if (this.Handle == System.IntPtr.Zero)
|
|
Win32.ThrowLastError();
|
|
}
|
|
|
|
private DesktopHandle(IntPtr handle, bool owned)
|
|
: base(handle, owned)
|
|
{ }
|
|
|
|
protected override void Close()
|
|
{
|
|
Win32.CloseDesktop(this);
|
|
}
|
|
|
|
public void SetCurrent()
|
|
{
|
|
if (!Win32.SetThreadDesktop(this))
|
|
Win32.ThrowLastError();
|
|
}
|
|
}
|
|
}
|