I solved my own issue. I found a web site that suggested putting
[TARGETDIR] into the registry view. That worked like a charm! It
stores the installation directory into the registry, which I retrieve
later on in my service.
-------------------------------------------------------------------------------
For a little background, I had written a service that checked whether
user's passwords were about to expire on our LDAP server. However, for
some reason, Windows Services seem incapable of handling the exception
correctly. Even though I would surround the entire service in try/
catch blocks, the exceptions would still terminate the program every
time. I am not sure if this is a Microsoft issue or a Novell issue.
Well, I tried a lot of things to prevent the service from stopping.
People on this forum were suggesting all kinds of crazy things and
none of their suggestions helped (some didn't make sense). Then
someone finally made me aware that Windows services operate with
different apartments than most applications. Somehow this affects how
services handle exceptions. That wonderful person suggested that I
separate the service code from the body code. However, they suggested
making a COM library and invoking it using some weird stuff I have
never heard of.
I took the simpler approach and just tried to make a library. However,
the library approach didn't work because the library methods were
being run under the service, which is essentially no different than
having them inside the service. I wasn't daunted, though, and I simply
made the library into a Console application and added a Main method.
Now my service simply executes the console application. Since Console
applications don't suffer from the strange exception handling gook
that services do, my errors are handling correctly . . . which means
my service has the benefit of just calling the console application
every some many hours. It is a nice separation of responsibility - now
I have a very nice shell for future services.
The only problem I had to figure out was how to get my service, which
runs with a path under System32 (that's default) to execute my console
application in my application directory. I simply put [TARGETDIR] in
the registry when the setup project runs and I can access it in my
service. Huzzah!
Thanks to everyone who tried to help me resolve my issue, I'm just
glad to be done with it, finally.
~Travis