Re: Windows Service Command Line Arguments?
bilaribilari@yahoo.com wrote:
2. In the executable path of the service (during CreateService)
instead of specifying just "foo.exe", I can specify "foo.exe arg1
arg2 arg3" as the path. This causes my executable to gt started with
the arguments.
However, when I try and get argc, argv in ServiceMain, I get argc=1
and that is the name of the service (not the executable name or path).
Arguments to ServiceMain do _not_ reflect parameters passed on the
command line. They reflect parameters configured for a service under
Services control panel applet (actually, parameters passed to
StartService).
You can still access command line arguments with GetCommandLine, of
course. This approach does not work for services in general because it's
possible for a single process to host multiple services, but it may work
in your case.
I would like to use the option 2 as far as possible and avoid reading
files. So how do I get the Image Path of the service?
If by "Image Path" you mean the full path to your executable, you can
use GetModuleFileName(NULL)
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925