You'd get that error if Perl was unable to find the Win32::EventLog class at runtime. E.g. if you create a script containing only the following, you can reproduce the error;

my $handle = Win32::EventLog->new("Application", $ENV{ComputerName});

ActivePerl doesn't seem come with Win32::EventLog by default - I just had to install in manually.

You can check whether it's installed by looking for the file;

C:\Perl\site\lib\Win32\EventLog.pm

(Assuming you installed ActivePerl to C:\Perl). The C:\Perl\site directory is where additional libraries, e.g. from CPAN, get installed while C:\Perl\lib is where the default libraries, bundled with Perl, are installed.

If it's not there, you'd need to install it - from the command line you start the ActiveState package manager then install the Win32::EventLogs;

C:\> ppm ppm> install Win32::EventLog

I assume you're not behind a proxy server. If you are you'd first need to setup your proxy environment in DOS, before running the above commands e.g.;

REM proxy.bat - set's up proxy environment vars @echo off set HTTP_proxy=http://your.company.proxy.com:8080/ set HTTP_proxy_user=user set HTTP_proxy_pass=passwd

If Win32::EventLog is installed, then you need to check you have the correct use statement at the start of the script;

use strict; use Win32::EventLog;

If Perl can't find it in it's library paths, it should raise an error at this point e.g.

Can't locate Win32/EventLog.pm in @INC (@INC contains: c:/Perl/lib c:/ +Perl/site/lib .) at print_log.pl line 2. BEGIN failed--compilation aborted at print_.pl line 2.

If you get that, run the following and post it here;

use Data::Dumper; print Dumper(@INC);

For a standard ActivePerl install you should see;

$VAR1 = 'c:/Perl/lib'; $VAR2 = 'c:/Perl/site/lib'; $VAR3 = '.';

In reply to Re: Win32::EventLog "fails" with no events? by harryf
in thread Win32::EventLog "fails" with no events? by dataking

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.