1

I've sadly inherited a shockingly bad application that randomly posts text to the clipboard.

Is there anyway in C# I can write an application/dll etc to stop process_name.exe accessing the clipboard?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
tripbrock
  • 952
  • 4
  • 13
  • 28
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Dec 13 '13 at 15:23
  • You may have better luck asking on [superuser.com](http://superuser.com) – Justin Dec 13 '13 at 15:23
  • @Justin: he says, "Is there anyway ... I can write an application" – John Saunders Dec 13 '13 at 15:25
  • 3
    Short answer: yes, you can use hooks: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644959%28v=vs.85%29.aspx ... but what app posts random text to the clipboard?! – user1567896 Dec 13 '13 at 15:27
  • 1
    This is a good way to turn a shockingly bad app into a complete Greek tragedy. Fix the problem. – Hans Passant Dec 13 '13 at 15:52
  • If I could fix it I would. The source was lost long ago and all we have is the exe file. Cheers for the input. – tripbrock Dec 13 '13 at 16:26
  • @HansPassant That analogy made me laugh quite a lot sir. – Francis Ducharme Dec 13 '13 at 18:01
  • @tripbrock - disassemble the exe? – scheien Dec 13 '13 at 18:03
  • Anything that you did to try to block it, would end up making things worse for other apps. It IS possible to deadlock the clipboard, such that nothing can copy/paste. The only way to make the clipboard "invisible" to your app, would be to hack the binary to jump around the clipboard API calls. That's definitely do-able. There are guys out there that can code around license checks and other software protection, so this would be child's play compared to that. – Chris Thornton Dec 13 '13 at 18:30
  • Continued.... I would caution you not to trust anyone who actually has the skills to do that, however. – Chris Thornton Dec 13 '13 at 18:30
  • @ChrisThornton Yes, you might have troubles finding consultants that will openly advertise as having such skills hehe. – Francis Ducharme Dec 13 '13 at 18:34

1 Answers1

1

Use AddClipboardFormatListener. Get the hWnd of the offending process's main window and pass it to the method. Now, will you be able to completely lock the clipboard, I don't know. But you'll probably be able to blank the clipboard or revert to the previous value at least when you detect that the offending app. has posted something to it.

More details here

But you should not really mess with the clipboard unless you only read from it. Locking/modifying it can cause a whole lot of other problems.

Community
  • 1
  • 1
Francis Ducharme
  • 4,848
  • 6
  • 43
  • 81
  • This led me on the right path although it happily track down processID's etc of apps you can copy and paste from - but the process ID of this troublesome EXE file is 0! – tripbrock Dec 16 '13 at 13:45
  • That is...weird. But anyhow, AddClipboardFormatListener does not take a Process ID as parameter, but rather, the window ID (HWND) of that process. Do a Google search on how to get the HWND of a process or open a new question as this won't be related to this original post anymore. – Francis Ducharme Dec 16 '13 at 14:01