Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting the return value (when installing a service)?

1 view
Skip to first unread message

jodleren

unread,
Nov 13, 2009, 6:19:42 AM11/13/09
to
Hi all

I have made a service, and it works (thanks to this NG)

They now want to have a return value when it installs or fails - is
that possible?
They have some batch files, and want to get the error level there?

How can I set the return value of my service or any normal windows
Delphi application?

I already looked here, the Halt() does not seem proper to me...

WBR
Sonnich

Maarten Wiltink

unread,
Nov 13, 2009, 6:37:55 AM11/13/09
to
"jodleren" <son...@hot.ee> wrote in message
news:33776bed-6965-4e61...@s15g2000yqs.googlegroups.com...

> I have made a service, and it works (thanks to this NG)
>
> They now want to have a return value when it installs or fails - is
> that possible?

Since you didn't write the code for what happens when you run it
in install mode, I doubt it.

Having concluded that it is impossible, the starting point to do it
anyway would be to dig into the assumption that you don't have an
'in' on the code for install mode. TService may well have an OnInstall
event. Read the help.


> They have some batch files, and want to get the error level there?
>
> How can I set the return value of my service or any normal windows
> Delphi application?

Googling for 'Delphi errorlevel' resulted in a list of hits, in the
second of which Rob Kennedy pointed out the ExitCode variable. (The
first hit was predictably concerned with reading, not setting, the
errorlevel.)

HOWEVER, a service is not a normal Windows application, is not called
synchronously from a batch file, and is in no position to usefully
set an errorlevel.

Groetjes,
Maarten Wiltink


Rob Kennedy

unread,
Nov 13, 2009, 10:37:37 AM11/13/09
to
Maarten Wiltink wrote:
> "jodleren" <son...@hot.ee> wrote in message
> news:33776bed-6965-4e61...@s15g2000yqs.googlegroups.com...
>> They have some batch files, and want to get the error level there?
>>
>> How can I set the return value of my service or any normal windows
>> Delphi application?
>
> Googling for 'Delphi errorlevel' resulted in a list of hits, in the
> second of which Rob Kennedy pointed out the ExitCode variable. (The
> first hit was predictably concerned with reading, not setting, the
> errorlevel.)
>
> HOWEVER, a service is not a normal Windows application, is not called
> synchronously from a batch file, and is in no position to usefully
> set an errorlevel.

It is if you make it a console program.

{$APPTYPE CONSOLE}

Now the batch file will pause while waiting for the service application
to finish installing itself:

ServiceApp.exe /install
if ERRORLEVEL 1 echo uh-oh

There's still a problem, though, which is that when a service fails to
install, it displays a dialog box. Even if you're installing the service
with a batch file, you can't have an unattended installation because
someone will need to be there to push the button.

That doesn't prevent the batch file from _also_ detecting failure,
though. In the service, set ExitCode to non-zero in the OnBeforeInstall
event. Set it to zero in the OnAfterInstall event; that event only gets
called if CreateService succeeds, so if it fails, you still have the
non-zero value from earlier.

Note that if there are multiple services in an application, the program
will try to install *all* of them, even if some fail along the way. And
if any fail, the successful ones won't get uninstalled.

Installation occurs during Application.Run. If it can't open the service
manager at all, then that function will terminate with an exception. If
the service manager opens OK but a service can't be installed,
Application.Run will terminate normally.

--
Rob

Erick Engelke

unread,
Nov 13, 2009, 10:17:37 PM11/13/09
to Rob Kennedy
On Fri, 13 Nov 2009, Rob Kennedy wrote:
>> HOWEVER, a service is not a normal Windows application, is not called
>> synchronously from a batch file, and is in no position to usefully
>> set an errorlevel.
>
> It is if you make it a console program.
>
> {$APPTYPE CONSOLE}
>
> Now the batch file will pause while waiting for the service application to
> finish installing itself:
>
> ServiceApp.exe /install
> if ERRORLEVEL 1 echo uh-oh
>
> There's still a problem, though, which is that when a service fails to
> install, it displays a dialog box. Even if you're installing the service with
> a batch file, you can't have an unattended installation because someone will
> need to be there to push the button.
>

There is another option you can specify in addition to /install
it's /silent or /quiet - I forget which. But it doesn't do a popup then.

Erick

Rob Kennedy

unread,
Nov 14, 2009, 12:14:03 PM11/14/09
to

It doesn't display a message upon *success*. On *failure*, though, it
still displays a message box. Check the code.

--
Rob

0 new messages