You could query the service through the Service Control Manager (SCM). In XP
(and I believe Win2k) there is a command line utility called SC that can
interact with a service. This is no different than using Win32::Service to
interact with a service. However this is pretty much just a way to interact
from outside of the service.
>From the service itself, if the call to Win32::Daemon::StartService() is
successful then you know that the service has been started and the SCM has
acknowledged that it is "starting up". Likewise when a call to
Win32::Daemon::State() returns SERVICE_START_PENDING then the SCM has
acknowledged the service is starting and expects you to reply by calling the
function passing in SERVICE_RUNNING. Once that is done your service is
officially started.
Since services run in a WinStation that is unseen there is effectively no
STDOUT to display printed data. However if you configure the service to run
as "LocalSystem" with the option set to "Allow service to interact with
desktop" then the service window will appear in the current logged on user's
WinStation thus it is viewable. You can use the following code to print to
the console:
Win32::Daemon::ShowService();
if( $Console = new Win32::Console() )
{
my %Hash;
GetServiceConfig( \%Hash );
$Console->Display();
$Console->Title( $Hash->{display} );
}
Once executed just print the to $Console buffer.
Something I do to test a running service is to print all output to a named
pipe. The server end of the named pipe is a perl script that accepts all
input and displays it on the screen.
<Plug>All this (and more) is described in the chapter on services in my
second book (http://www.roth.net/books/handbook/ ).</Plug> ;)
Cheers,
dave
-----Original Message-----
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 26, 2002 7:14 AM
To: [EMAIL PROTECTED]
Subject: Service started by ...
Does anyone know how can I test in a program whether it has been
started as a service (I am using Win32::Daemon) or from the
command line? I'd like to
1) Fake the Service Manager's message during startup
2) Print the loggin messages to STDOUT as well as the log file
when running from cmdline.
Being able to get the name of the process that started by program
would be enough. Even if you only know how to do that in C.
Thanks, Jenda
=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ========== There
is a reason for living. There must be. I've seen it somewhere. It's just
that in the mess on my table ... and in my brain I can't find it.
--- me
_______________________________________________
Perl-Win32-Admin mailing list [EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs