Hello,
I have code that uses WMI NextEvent to monitor event log activity on Windows systems.

I am useing Activestate Perl Service module (PerlSvc from thier Developers kit) to make it into a service. The servce runs fine but the service will not stop normamly. You have to manualy kill the process PID.

Active State Tech Support said: "It looks then like NextEvent is blocking in such a way that it doesn't respond to the service control commands, at least with your implementation."

The service stops OK if I use the NT Resource kit SRVANY, but I'd rather not use SRVANY because it is a seperate process and not as reliable as a perl based soloution.

I'd would appreciate any ideas to get this working or alternate methods that do not use the Active State perlsvc. Following is sample test code.

package PerlSvc; our %Config = (ServiceName => "TestService"); require Getopt::Long; $PerlSvc::Verbose = 0; # Put PerlSvc into quiet mode sub Startup { Getopt::Long::GetOptions('interval=s' => \$interval); #main::Init(); while(ContinueRun()) { # $ main::testservice(); # } } sub Interactive { # this callback is invoked when your service is not running as # a service and has been called without any of the --help, # --install or --remove options. Install(); Startup(); } sub Pause { # your service is about to be suspended } sub Continue { # your service will resume execution now } sub Install { Getopt::Long::GetOptions( 'interval=s' => \$interval, ); $Config{ServiceName} = "TestService"; $Config{DisplayName} = "TestService"; $Config{Description} = "TestService"; # add your additional install messages or functions here } sub Remove { # add your additional remove messages or functions here } sub Help { # add your additional help messages or functions here } package main; sub testservice { ################################################ Begin Program # +################################################# use Win32::OLE qw(in); my $evtQuery = "SELECT * FROM __instancecreationevent WHERE targetinst +ance ISA 'Win32_NTLogEvent' and (targetInstance.EventIdentifier= '592 +')"; my $Events = Win32::OLE->GetObject("WinMgmts:{impersonationLevel=imper +sonate,(security)}")-> ExecNotificationQuery($evtQuery) || warn + Win32::OLE->LastError; while (my $Event = $Events->NextEvent) { open (LOG, ">>testservice.log") || die "Could not Open testservice +.log"; print LOG ((localtime)." A new Process has been created\n"); close (LOG); return unless PerlSvc::ContinueRun(); } ############################################### END Program ##### +############################################### }

janitored by ybiC: Minor layout tweaks including balanced <readmore> tags


In reply to Problem Stopping Service using Active State Perlsvc by spaziwk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.