billyChou Posted December 18, 2016 Share Posted December 18, 2016 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. 1 Quote Link to comment Share on other sites More sharing options...
Skepsis IT Posted December 18, 2016 Share Posted December 18, 2016 Hmm, I think that not going to work. I am not 100% sure but windows services cannot interact with the desktop. It's a kind of isolated. Google it a little bit, if you find another solution Quote Link to comment Share on other sites More sharing options...
mhmda Posted December 18, 2016 Share Posted December 18, 2016 I think your question is not clear enough... Can you explain. Quote Link to comment Share on other sites More sharing options...
billyChou Posted December 18, 2016 Author Share Posted December 18, 2016 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 Quote Link to comment Share on other sites More sharing options...
Wilton Ergon Posted March 17, 2017 Share Posted March 17, 2017 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.