troubleshooting Question

TService can't capture screen and running others application correctly

Avatar of Narinnat
Narinnat asked on
Delphi
5 Comments1 Solution577 ViewsLast Modified:
Hi I got a trouble with TService application, I want to make an agent to capture screen and running other application by using ShellExecute function but the result is the image I captured contains no picture and any application which I called from ShellExecute or WinExec function can't be display on the Windows desktop but it run in the memory instead, However when I run the application outside calling from TService it can be display correctly. How can I fix this??

procedure TW_Main.ServiceStart(Sender: TService; var Started: Boolean);
begin
  WinExec('OfficeAgent.Exe', SW_HIDE);
end;



My Screenschot function inside the OfficeAgent.exe:

Procedure TW_Main.ScreenShot;
var B:TBitmap;
    jp: TJPEGImage;
    Error : integer;
    ErrorMsg:String;
    DC:HDC;
begin

   ErrorMsg:='';
   B := TBitmap.Create;
   B.Width := GetSystemMetrics(SM_CXSCREEN);
   B.Height := GetSystemMetrics(SM_CYSCREEN);  

   DC:= GetDC(GetDesktopWindow);
   BitBlt(B.Canvas.handle, 0, 0, B.Width, B.Height, DC, 0, 0, SRCCOPY);

   jp := TJPEGImage.Create;
   jp.Assign(B);


   jp.Scale:= jsFullSize;
   jp.CompressionQuality:=60;
   jp.JPEGNeeded;

   try
   Jp.SaveToFile(DownloadDir+'\'+AGENTID+'.jpg');


    try

        ErrorMsg:=UpLoad(DownloadDir+'\'+AGENTID+'.jpg');

    finally
     try
      if ErrorMsg<>'' then
         SendMessage(ErrorMSG)
          else SendMessage('SCREEN&#Upload\'+AGENTID+'.jpg');
     except
     end;

    end;

   finally
    Jp.Free;
    B.Free;
   end;


end;
ASKER CERTIFIED SOLUTION
geobul

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros