Jump to content

Service run another application


billyChou

Recommended Posts

Standalone Server can run another application.

-------------------------------------------------------------

Procedure WinExecAndWait(CommandLine:String);
var ComLineBuffer: array[0..512] of char;
    StartupInfo: TStartupInfo;
    ProcessInfo: TProcessInformation;
    Re:Cardinal;
begin
  StrPCopy(ComLineBuffer,CommandLine);
  FillChar(StartupInfo, Sizeof(StartupInfo), #0);
  StartupInfo.cb := Sizeof(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := SW_HIDE;
  if CreateProcess(nil,
                   ComLineBuffer,          { pointer to command line string }
                   nil,                    { pointer to process security attributes }
                   nil,                    { pointer to thread security attributes }
                   True,                   { handle inheritance flag }
                   CREATE_NEW_CONSOLE or   { creation flags }
                   NORMAL_PRIORITY_CLASS,
                   nil,                    { pointer to new environment block }
                   nil,                    { pointer to current directory name, PChar}
                   StartupInfo,            { pointer to STARTUPINFO }
                   ProcessInfo)            { pointer to PROCESS_INF }
     then
  begin
    WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Re);
    CloseHandle(ProcessInfo.hProcess);  { to prevent memory leaks }
    CloseHandle(ProcessInfo.hThread);
  end;
  end;           

------------------------------------------------------------------------

 

 

Windows Service Server can run not  another application.

 

Thanks.

 

 

 

  • Upvote 1
Link to comment
Share on other sites

Standalone Server can run another application ->call custome report.exe  report.file  generate report.pdf  -> ok

 

Service mode   can run another application->call custome report.exe  report.file  generate report.pdf      ->   ok  ( can run in backgroud)

 

 

bRet := WinExecAndWait32(sExec, 0);

 

command line is

 

D:\myProj\EDragon\Tools\Rpt_Tools\RoneHo3.exe   (space )

D:\MYPROJ\EDRAGON\TOOLS\RPT_TOOLS\EPO110R1.RH3 -I:S_STNO_FM,'A128512531';S_STNO_TO,'X220567374'; -OD:R-222844-593

------------------------------------------------------------------------------------------------------------------------------------------

 

function WinExecAndWait32(FileName: string; Visibility: integer): boolean;
var
  ComLineBuffer: array[0..512] of char;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  fResult: dword;
  h      : thandle;
begin
  Result := false;
  StrPCopy(ComLineBuffer,FileName);
  FillChar(StartupInfo, Sizeof(StartupInfo), #0);
  StartupInfo.cb := Sizeof(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK ;
  StartupInfo.wShowWindow := Visibility;
  h := 0;
  //if CreateProcess(nil, PChar(Filename), nil, nil, false,
  //   CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil,
  //   StartupInfo, ProcessInfo) then
  if CreateProcessAsUser(h,nil, ComLineBuffer, nil, nil, false,
     NORMAL_PRIORITY_CLASS, nil, nil,
     StartupInfo, ProcessInfo) then

  begin
    WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, fResult);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
    Result := true;
  end;
end;

-------------------------------------------------------------------

New problam  -> can not  generate report.pdf (about File Create Permissions)

 

Thanks

Link to comment
Share on other sites

  • 2 months later...

try this

 

procedure TfrmReportFilter.ExecutaReport;
var
  AUrl2,AUrl,  File_Exit: string;
 conta, r:integer;
begin
AUrl         :='';
File_Exit :=UniServerModule.NewCacheFileUrl(False, 'pdf', '', '', AUrl, True);
 
if not UniMainModule.dbsmain.connected then
    UniMainModule.dbsmain.open;
 
// my runreport is create with report builder, generate pdf (file_exit)
 
unimainmodule.ExecAndContinue(UniMainModule.diratual+'RunReport.exe',
           ' "'+inttostr(idreport)+' "'+
           ' "'+UniMainModule.ParamReport1+' "'+
           ' "'+UniMainModule.ParamReport2+' "'+
           ' "'+UniMainModule.dbsmain.Server+'|'+UniMainModule.dbsmain.Database+'|'+UniMainModule.dbsmain.Username+'|'+UniMainModule.dbsmain.Password+' "'+
           ' "'+File_Exit+' "',
           SW_SHOWMINIMIZED);
 
conta :=0;
While TRUE DO
  BEGIN
    if FILEEXISTS(File_Exit) then
       begin
         try
         r :=FileOpen(File_Exit,fmExclusive);   ' open exclusive, its ok!!!!!!
         if r>0 then
            begin
             FileClose®;
             break;
            end;
         except
         end;
       end;
    Sleep(500);
    inc(conta);
    if conta>600 then
       begin
         aUrl :='';
         break;
       end;
 
  END;
 
if aUrl='' then
   begin
     showmessage('Report not genereted',nil);
     exit;
   end;
 
AUrl2  :='/pdf/web/viewer.html?file='+AUrl+'#page=1&zoom=100';   //  USE ATACHED FILE!!!!!!
 
 
frmReportPreview.LinkReport.URL :=AUrl2;   // LinkReport its  a TUniURLFrame
frmReportPreview.ShowModal;
Cancelou :=FALSE;
UniMainModule.dbsmain.close;
Close;
 
 
.
.
.
.
 
 
 
procedure TUniMainModule.ExecAndContinue(Nome, Parametros: String;Janela:Word);
Var
 Comando: Array[0..1024] of Char;
 Parms: Array[0..1024] of Char;
begin
  StrPCopy (Comando, Nome);
  StrPCopy (Parms, Parametros);
  ShellExecute (0, Nil, Comando, Parms, Nil, Janela);
end;

 

 

 

pdf.rar

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...