Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using CreateProcess to run report

Posted on 1998-03-17
4
Medium Priority
?
219 Views
Last Modified: 2010-04-06
Hi

My application has to launch Paradox (any version) and run a report. I am fighting a losing battle to get CreateProcess to work. However, I still want to use this call. How do I get it to work? Assume I have the path to the correct version. Part 2: How can I disable my app from opening another version of this report; don't say, disable the button, because I still need to re-enable it, which brings us back to the same problem.
0
Comment
Question by:Edo082297
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:d003303
ID: 1360539
Why are you so bound on the CreateProcess commend ? Why don't you use OLE automation to solve this problem ?

Slash/d003303
0
 
LVL 1

Accepted Solution

by:
Greedy earned 300 total points
ID: 1360540
just make a call to this

function WinExecAndWait32(FileName:String; Visibility : integer):integer;
//  filename is the name of the executable and path if needed.
//  Visibility is how the window should be displayed.
//  1 = normal with focus
//  2 = minimized
//  3 = maximized
//  4 = normal/ no focus

var
  zAppName:array[0..512] of char;
  zCurDir:array[0..255] of char;
  WorkDir:String;
  StartupInfo:TStartupInfo;
  ProcessInfo:TProcessInformation;
begin
  StrPCopy(zAppName,FileName);
  GetDir(0,WorkDir);
  StrPCopy(zCurDir,WorkDir);
  FillChar(StartupInfo,Sizeof(StartupInfo),#0);
  StartupInfo.cb := Sizeof(StartupInfo);

  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil,
    zAppName,                      { pointer to command line string }
    nil,                           { pointer to process security attributes }
    nil,                           { pointer to thread security attributes }
    false,                         { handle inheritance flag }
    CREATE_NEW_CONSOLE or          { creation flags }
    NORMAL_PRIORITY_CLASS,
    nil,                           { pointer to new environment block }
    nil,                           { pointer to current directory name }
    StartupInfo,                   { pointer to STARTUPINFO }
    ProcessInfo) then Result := -1 { pointer to PROCESS_INF }

  else begin
    WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess,Result);
  end;
end;

0
 
LVL 1

Author Comment

by:Edo082297
ID: 1360541
I am using CreateProcess for this because I need to instantiate a separate thread for the WaitForSingleObjectEx call. I do not want the user playing with the 'main' application while the Paradox portion is going, d003303.


0
 
LVL 1

Author Comment

by:Edo082297
ID: 1360542
I am using CreateProcess for this because I need to instantiate a separate thread for the WaitForSingleObjectEx call. I do not want the user playing with the 'main' application while the Paradox portion is going, d003303.

I grade Greedy's answer as good, only because I got it to work with less code. Is this better? Perhaps not. I used GetStartupInfo instead of intializing the STARTUP_INFO structure myself (is this necessary?), and because I am not sure of the role of zCurDir and WorkDir. Also, why is the WaitForSingleObject call in an else portion? Isn't this counter-intuitive, or is this the way it's done? While you're at it, greedy, could I have used OLE automation to do this? Would I want to?


0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question