Copy-Paste clipboard does not work in service on Win Server 2008 / Vista 64bit

Update: This issue has been resolved.

you can read about the solution here: Creating a process in a non-zero session from a service in a Windows 2008 server?

Thanks everyone!


Hi,

I am trying to use the clipboard API (in Delphi) to extract images from Word documents. my code works fine on Windows XP / 2003, but on Windows 2008 64 bit it doesn't work. in win 2008 I get a message that Clipboard.Formats is empty and does not contain any format.

The image seems to be copied to the clipboard (I see it on the clipboard via Word), but when I try to ask the clipboard what format it says, it does not have any formats.

How can I access the buffer programmatically on win 2008 / Vista? from what I know about the 64-bit version of 2008, it could be a security issue ...

here is the code snippet:

This is how I try to copy the image to the clipboard:

W.ActiveDocument.InlineShapes.Item(1).Select; // W is a word ole object
W.Selection.Copy;

and this is how i try to insert it.

  Clipboard.Open;
      Write2DebugFile('FormatCount = ' + IntToStr(Clipboard.FormatCount)); // FormatCount=0 
      For JJ := 1 to Clipboard.FormatCount Do
          Write2DebugFile('#'+ IntToStr(JJ) + ':' + IntToStr(Clipboard.Formats[JJ]));
      If (Clipboard.HasFormat(CF_BITMAP)) or
        (Clipboard.HasFormat(CF_PICTURE)) or
        (Clipboard.HasFormat(CF_METAFILEPICT)) then    // all HasFormat calls returns false.
      Begin
       Jpeg := TJPEGImage.Create;
       Bitmap := TBitmap.Create;
       Bitmap.LoadFromClipboardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);
       Jpeg.Assign(Bitmap);
       Jpeg.SaveToFile(JpgFileN);
       try Jpeg.Free; except; end;
       ResizeImage(JpgFileN,750);
       Write2DebugFile('Saving ' + JpgFileN);
      End
      else  Write2DebugFile('Doesnt have the right format');

Thanks in advance, Itai

+3
source share
1 answer

AFAIR, it seems that M $ does not allow services to interact with the desktop (which is necessary to use the clipboard) in Win2008.

+2
source

Source: https://habr.com/ru/post/1731213/


All Articles