Skip to content

Instantly share code, notes, and snippets.

@koffeinfrei
Created November 21, 2011 08:28
Show Gist options
  • Save koffeinfrei/1382028 to your computer and use it in GitHub Desktop.
Save koffeinfrei/1382028 to your computer and use it in GitHub Desktop.
Gets the process that locks the clipboard (i.e. openened but didn't close it)
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace ConsoleApplication1
{
public class Program
{
[DllImport("user32.dll")]
static extern IntPtr GetOpenClipboardWindow();
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int
lpdwProcessId);
public static void Main(string[] args)
{
IntPtr hwnd = GetOpenClipboardWindow();
if (hwnd != IntPtr.Zero)
{
int processId;
GetWindowThreadProcessId(hwnd, out processId);
Process p = Process.GetProcessById(processId);
Console.WriteLine(p.Modules[0].FileName);
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment