Delphi: How to open Batch file in Thread (Windows Service)

364 Views Asked by At

I wrote a Windows Application and now I want to transform it into a Windows Service. In my Windows Service Program I have a thread which should open a batch file. Normally I open batch files with Shell Execute:

ShellExecute(Handle, 'open', PWideChar('myPath'), nil,nil, SW_Hide);

But I can not use SW_Hide in my thread. Is there any other way opening a batch file in a thread or am I using the correct approach?

1

There are 1 best solutions below

4
On

Is there any other way opening a Batch file in a Thread

You can open a batch file by the following command line:

cmd.exe /c mybatch.bat arg1 arg2 arg3

And you can start this from your thread using Windows API CreateProcess.