1

Good afternoon to all.

I want see a window that is open inside of a "new desktop environment", from of my remote assistance tool, but I'm not able to see this window using conventional functions like this below:

    function RandomPassword(PLen: Integer): string;
    var
      str: string;
    begin
      Randomize;
      str    := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
      Result := '';
      repeat
        Result := Result + str[Random(Length(str)) + 1];
      until (Length(Result) = PLen)
    end;

        procedure Printscreen;
        var
          DCDesk: HDC;
          bmp: TBitmap;
          hmod, hmod2 : HMODULE;
          BitBltAPI: function(DestDC: HDC; X, Y, Width, Height: Integer; SrcDC: HDC; XSrc, YSrc: Integer; Rop: DWORD): BOOL; stdcall;
          GetWindowDCAPI: function(hWnd: HWND): HDC; stdcall;

          begin

         hmod := GetModuleHandle('Gdi32.dll');
         hmod2:= GetModuleHandle('User32.dll');

         if (hmod <> 0) and (hmod2 <> 0) then begin

          bmp := TBitmap.Create;

          bmp.Height := Screen.Height;
          bmp.Width := Screen.Width;

          GetWindowDCAPI:= GetProcAddress(hmod2, 'GetWindowDC');

          if (@GetWindowDCAPI <> nil) then begin

            DCDesk := GetWindowDCAPI(GetDesktopWindow);

          end;

          BitBltAPI:= GetProcAddress(hmod, 'BitBlt');

          if (@BitBltAPI <> nil) then begin

            BitBltAPI(bmp.Canvas.Handle, 0, 0, Screen.Width, Screen.Height, DCDesk, 0, 0, SRCCOPY);

            bmp.SaveToFile('ScreenShot_------_' + RandomPassword(8) + '.bmp');

          end;

            ReleaseDC(GetDesktopWindow, DCDesk);

            bmp.Free;

            FreeLibrary(hmod);
            FreeLibrary(hmod2);

         end;
        end;

begin
   while True do
    begin
       Printscreen;
      Sleep(5000);
    end;

end.

That produces this result

Already using Team View software for example, the window appears on screen capture normally and produces this result.

So, exist some way for see this window in screen capture like is possible from of Team View software?

All suggestions will be welcomed.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Call Randomize exactly once in the life of your program or you will get some nasty surprises. Try calling RandomPassword in a loop. – David Heffernan May 21 '16 at 19:50
  • [This is the app that open this window](https://www.itau.com.br/computador/) –  May 21 '16 at 19:54
  • "graphics" already uses "windows", you won't gain anything by not using declared functions in "windows". – Sertac Akyuz May 21 '16 at 22:01

1 Answers1

5

It seems that you are trying to get the screenshot of a secure desktop. If that is the case first you must read the documentation about this topic. Because this is not a trivial task (you must know about Sessions, Desktops and Windows Stations). Also your application must be a trusted process running from the Local SYSTEM Account.

From here now you must do this.

Recommended Lecture

Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • you is right, I will go to study about this. But if someone (or youself) want put here some fragmento de código, for help understand better about this. –  May 21 '16 at 20:49
  • You must try to write the code and then go back with a new question if you found a problem. But first start reading the docs. – RRUZ May 21 '16 at 20:55
  • with reference to my code above and explanation of all doc that you suggested above, is possible get screenshots just of `Session 0` with this my code make, is right? –  May 21 '16 at 21:18
  • 1
    The current code is not able to work properly because you have several flaws, first you must trap the exceptions and protect the system resources using `try..finally` and `try..except` blocks. Also you must move you screen capture code to a secondary thread, because you must call the `SetThreadDesktop` method to switch to the active desktop and capture the screen. – RRUZ May 21 '16 at 21:34
  • Based in all that you said, I found [this relevant question](http://stackoverflow.com/questions/6780593/why-the-screenshot-doesnt-work-black-screen) here in S.O. This will help me so much, mostly in dll injection process. –  May 22 '16 at 00:19
  • Dll injection.. Then why do you care taking a screen shot from a different desktop? The code will run in the process that created that desktop. I guess you haven't yet decided in what way you'd access card information. – Sertac Akyuz May 22 '16 at 03:18
  • @SertacAkyuz, this process that create this Winstation is protected against dll injection :-(. So as suggested on last answer in relevant question that I showed before, for this capture works fine in WinSta0, will be necessary make a dll injection in a process that can run like trusted, eg: cmd.exe –  May 22 '16 at 13:49