Monday 23 July 2018

windows - How to check which application has the clipboard hold?


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.



Answer



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 :


 _
Public Function GetOpenClipboardWindow() As IntPtr
End Function
_
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.


No comments:

Post a Comment

Where does Skype save my contact&#39;s avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...