How to? clipbboard is locked

Oct 18, 2008
273
1
#1
Hello -- I came across a scenario were the command ( in a batch file )

"ver /r > clip:"

failed and the error message was the clipboard file was in exclusive use -- is there a way to debug this to see
which process has the lock on it?

Thanks
 
#2
GetOpenClipboardWindow function
Code:
echo %@winapi[user32.dll,GetOpenClipboardWindow]
This returns the handle to the window that has the clipboard open.

The SysUtils plugin has the WHICHWIN command, from which you can determine the handle of the window that has the clipboard open.
Code:
WHICHWIN: find windows and show their properties; options:

  /F format_elements (lowercase supresses description)

     elements:   H(andle)  P(rocess)  C(lass)   M(odule file name)
       T(itle)   V(isible)  S(how)    L(TRB normal)
       I(ndex)   D (thread) B(lank)   E(nabled)
       N(umber found/processed)

     default:   HPMCTVSLBEN

  /R       recurse (do child windows)
  /nnn       maximum number of windows to return

  Filters:

  /E | /D   enabled | disabled windows only
  /V | /I   visible | invisible windows only
  /P pid   decimal or hex prefixed with "0x"
  /M module   case-insensitive substring match on fully-qualified name
  /C class   case-insensitive substring match
  /T title   case-insensitive substring match
       "quote" strings containing spaces
Not sure if this solution will work for you, but worth a try.

Joe
 
#3
This quick-and-dirty .BTM shows how to Open the Clipboard, lock it, and then find out which window has the clipboard locked;
Code:
@setlocal
@echo off

set hwnd=%@winapi[user32.dll,GetOpenClipboardWindow]
iff %hwnd eq 0 then
  echo Clipboard is not locked.
else
  echo Clipboard is locked by window handle %hwnd
  quit
endiff

Gosub GetTCMDhwnd

:: Open the Clipboard
set rc=%@winapi[user32.dll,OpenClipboard,%@eval[%handle]]
iff %rc eq 0 then
  echo Could not open clipboard.
  quit
else
  echo Clipboard has been opened.
endiff

:: Empty the Clipboard
set rc=%@winapi[user32.dll,EmptyClipboard]
iff %rc eq 0 then
  echo Could not empty clipboard.
else
  echo Clipboard has been emptied.
endiff

:: Is the clipboard locked?
set hwnd=%@winapi[user32.dll,GetOpenClipboardWindow]
iff %hwnd eq 0 then
  echo Clipboard is not locked.
else
  echo Clipboard is locked by window handle %@eval[%hwnd=H]
endiff

::Close the Clipboard
set rc=%@winapi[user32.dll,CloseClipboard]
iff %rc eq 0 then
  echo Could not close clipboard.
else
  echo Clipboard closed.
endiff
endlocal
quit

:GetTCMDhwnd
iff PLUGIN sysutils then
  ::Next Sentence
else
  plugin /l c:\utils\sysutils64.dll
endiff

iff %_? eq 0 then
  ::Next Sentence
else
  echo Could not load SysUtils plugin
  quit
endiff

set handle=%@execstr[whichwin /v /T "Administrator: TC 22 - TCC Prompt"]
iff %@word[0,%handle] eq Handle: then
  set handle=%@word[1,%handle]
  echo hwnd for "Administrator: TC 22 - TCC Prompt" is %handle
else
  echo Could not get handle to TCMD.EXE
  quit
endiff
Return
Note that I am using TCMD with the title "Administrator: TC 22 - TCC Prompt" for the window to be associated with the open clipboard.

You may (probably will) have to change that.

Modify the code to meet your requirements.

Joe