cheshirecat has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I'm having problems with using Win32::AdvNotify in a perl script that is meant to run as a Win32 service on a win2k box.

I'm trying to write a script that will watch a directory and all it's sub directories for any changes to the filesystem.
When the filesystem changes, the script should then login via ftp to our webserver box and update the files there.

The win2k box is our content management server.

I want the script to run as a service so that it

  1. Starts automatically when the server starts
  2. Does not need anyone to login (ie no console)
Any thoughts ? and I have tried to contact the author but no luck there

The Cat

Replies are listed 'Best First'.
Re: Win32::AdvNotify problems
by Jenda (Abbot) on May 29, 2002 at 13:49 UTC

    Erm ... and what is actualy the question?

    You do not know how to create a service? - See Win32::Daemon

    You do not know how to use Win32::AdvNotify? - It comes with docs including an example.

    You do not know how to FTP the files? - Net::FTP

    Win32::AdvNotify works fine when you run the script from command line, but not when you run it as a service? Did you check permissions? Do you "compile" the script using PerlApp, PerlSvc or Perl2Exe? If so you should keep in mind that Amine's modules are NOT developed using XS. The DLL is in plain C (or C++) and is loaded and accessed using Win32::API. This means that it is not automaticaly included by PerlApp/PerlSvc/Perl2Exe and that it is not looked up correctly.

    I am afraid you'll have to bind it into the .exe explicitely, maybe extract it somewhere on the disk yourself with PerlApp::BoundFile() (maybe the name's a bit different) and change $Win32::AdvNotify::DLLPath BEFORE you create the first Win32::AdvNotify object so that the DLL is found.

    Please let us know where the problem is and what is it.

      Jenda

      Jenda,

      Thanks for the comprehensive reply, I'm sorry I didn't make the question clear.

      I can create a service using Win32::Daemon and have done so successfully. I have built an application using both Win32::AdvNotify and Net::FTP to syncronise the content management server with the webserver. This application is currently run as a console application where the Win2k Server has been logged in.

      I am now try to make the application a service so our IT guys do not have to log in to start the application.

      The problem appears to that Win32::AdvNotify requires a console window and as the service will be running without being logged in, there will be no console.

      I have investigated the perl code in Win32::AdvNotify and I have tried replacing use Carp; with use CGI::Carp qw(carpout); but still no luck.

      I have not compiled the script, I am just running it under the windows services control panel (ie I have installed it as a service).

      I hope this makes my problem clearer.

      Regards
      The Cat

        • But you are positive the script runs, right?
        • Under what account does the service run? Did you try to run it under the account of the user that it was running under before?
        • Do you get any errors somewhere?
        • What about if you redirect both STDOUT and STRERR to a log file in a BEGIN{} block on top of your script? Do you see anything there then?
        • Do you try to access any mapped drives or UNCs from the script? While the second should work fine if you run the service under a domain account, the first is doomed to fail. As you may know, the drives are mapped per user session, so the service doesn't see them. And I believe even if they were set as "persistent" for the user the service runs under they would not be available.

        I do not see any reason why would Win32::AdvNotify require a console. I'd think permissions are a much more likely culprit.

        If you think it is the console and you run the service under LocalSystem account you may try to "Allow service to interact with desktop". That should allow it to create a console, though maybe it will be visible only if there is someone loged on.

          Hope one of the wild guesses will help :-)
          Jenda

Re: Win32::AdvNotify problems
by mumbles (Friar) on May 29, 2002 at 10:17 UTC
      I have looked at this and it has its problems.

      DirMon.pl scans the entire directory tree and then compares it to it's previous file list to find changes.

      This can be a bit of a problem with over 13,000 files in our website and it brings the content management server to it's knees every time the directory scan is done.

      Thanks all the same

      The Cat