Is it possible to run a hidden console application from a Windows service?
I've written a开发者_如何学JAVA server in Delphi 2010 that needs to launch a console application every now and again to back up a database. The console application can send log information to the console window, but it is not required.
This works fine when running as an application, but when run as a service I get an access violation when launching the console application. This is the case even if I launch it hidden (SW_HIDE).
Is it possible to launch a hidden console application from a Windows service? The solution needs to work on XP, Vista and Windows 7.
EDIT: The access violation happens when I call ShellExecute.
If you are using ShellExecute
, then don't: it won't work inside a service, and is almost never the best way to start a process.
Use CreateProcess
in stead.
See this bunch of ShellExecute / CreateProcess question threads on stackoverflow.
--jeroen
精彩评论