Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having a delphi service start an applicaiton

Status
Not open for further replies.

john230873

Programmer
Oct 3, 2003
89
NZ
I have an delphi program that runs as a service, I would like this service to start up an applicaton and display its form on the console screen. I am using the createprocess API but all I can do is create another service it wont create an application.
 
I've used ShellExecute no problem from a service application. Just set the handle parameter = 0.
 
actually.... maybe I haven't. But I know this code works:

function WinExecAndWait32(FileName: string; Visibility: Integer): dWord;
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 := 0 { pointer to PROCESS_INF }
else
begin
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
end;
end;
 
To Griffin:

I tried your code from a CGI app using it to start Excel and Excel hangs, presumably because it cannot find a window to activate.

I used your code verbatim, except for the value you passed to it "visibility".

Is there some secret to getting the resultant application to have a "window" when starting from a CGI app?

TIA,
JGS
 
John:

Well, I have a message queueing unit which writes "files" as message queues and I started another small gui delphi app that just timer-wise reads the queues and writes the message into a pchar array and then issues CreateProcess and that works....

LESS than elegant... but...

JGS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top