1

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 Answers1

2

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.

fpiette
  • 11,983
  • 1
  • 24
  • 46
  • Wouldn't that show Command prompt window? Based on OP question I have a feeling that he would like to execute batch file in background without showing any window. – SilverWarior Oct 05 '20 at 13:28
  • @SilverWarior: One of the options in CreateProcess is to create the window hidden, but if OP can't use SW_HIDE in ShellExecute, I wonder if he can use it in CreateProcess... – HeartWare Oct 05 '20 at 14:00
  • @HeartWare He didn't told why he cannot use in ShellExecute, but for sure it can be used in CreateProcess. Maybe he can't since his application is a service? I wonder if his problem is not the shell which probably is not there for a service. – fpiette Oct 05 '20 at 14:05
  • @fpiette thanks for your answer. So I wrote a normal windows application and now I want to transform it into a service. After I embedded the shell Api I had no error. Only SW_Hide was underlined. I will try Crate Process now :) – Sebastian Schwayer Oct 06 '20 at 07:32