How to check which application has the clipboard hold?

8

1

We are deploying some virtual machines with robots software which performs actions in a browser, and we are having trouble with some of them when accessing the clipboard for read or write. They show a "Cannot open clipboard".

So there is any other application holding the clipboard.

How can we debug that? Is there any tool which can monitor that? AFAIK ProcMon doesn't do the job.

Machines are Windows XP.

Áxel Costas Pena

Posted 2014-06-18T16:25:02.010

Reputation: 761

@Ramhound machine has a lot of components much of which are needed for the robot activity. Starting from a clean machine and install the software one by one until reproducing the bug will be very expensive. – Áxel Costas Pena – 2014-06-19T12:36:19.550

@Wutnaut not sure what you are thinking of, I think this doesn't apply to that, robot fills web forms by writing to clipboard and pasting its contents – Áxel Costas Pena – 2014-06-19T12:36:54.190

@all we finally found it was the vncserver's fault. Even explicitly disabling its clipboard sharing feature. Anyway the question was explicit and I am interested anyway in finding an answer, so the question remains open – Áxel Costas Pena – 2014-06-19T12:40:17.710

@ÁxelCostasPena - Sounds like you already have your answer. You had a service being loaded that was causing the conflict. I never told you to start with a "clean" machine. I told you to boot using only the software you need. If you had done that, and it worked, you would have a list of possible problem children. When it didn't work you would also have a list. – Ramhound – 2014-06-19T13:10:12.610

@Ramhound yeah I solved your problem, but I'd love to find if is there any way to ask windows who has a clipboard open, and even monitor clipboard accesses – Áxel Costas Pena – 2014-06-19T17:06:23.503

I do believe there are applications that exist to monitor clipboard access. – Ramhound – 2014-06-19T18:01:34.027

I simply don't know, but it's hard to believe there aren't. But two hours of google gave me no one tool – Áxel Costas Pena – 2014-06-20T08:01:46.737

Does this happen in a minimal boot configuration? – Ramhound – 2014-06-18T16:27:47.890

The robots software doesn't work in safe mode, that is one of the difficulties – Áxel Costas Pena – 2014-06-18T16:45:46.080

1I didn't say Safe Mode I said in a minimal boot configuration there is a difference. – Ramhound – 2014-06-18T16:48:26.670

Manual clipboard: save the text to a file, call the text in that file, delete the file. – Wutnaut – 2014-06-18T17:20:31.760

Answers

8

The Clipboard API dates from Windows 3.0 (or before?) and is badly designed. Unfortunately, instead of having get/set primitives, it uses open/close, which makes it possible for applications to hold its access for far too long. Some improvement was brought by Vista to the handling of the viewers chain, but no new API.

With the existing API, it is possible to identify the owner of the clipboard only if that owner also has at least one open window. If the owner has no windows, then one is out of luck.

In the thread Why has my clipboard stopped working?, Jay Parzych has contributed the following vbs code where the GetClipboardLocker function returns the file-name of the process holding the clipboard :

<DllImport("user32.dll")> _
Public Function GetOpenClipboardWindow() As IntPtr
   End Function
 <DllImport("user32.dll", SetLastError:=True)> _
   Public Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer
   End Function
Public Function GetClipboardLocker() As String
       Dim hwnd As IntPtr = GetOpenClipboardWindow()
       If hwnd <> IntPtr.Zero Then
           Dim processId As Integer
           GetWindowThreadProcessId(hwnd, processId)
           Dim p As Process = Process.GetProcessById(processId)
           GetClipboardLocker = p.Modules(0).FileName
       Else
           GetClipboardLocker = String.Empty
       End If
   End Function

A similar C# function can be found in the post Get Clipboard owners Title/Caption.

harrymc

Posted 2014-06-18T16:25:02.010

Reputation: 306 093

Since in our scenario, we can assure that any process that is doing that has no window created, I'll mark it as right answer. Thank you. – Áxel Costas Pena – 2016-06-13T11:08:06.177