Tobias,

Thanks for your response.  In the ensuing time since I
posted the query, I've received some assistance and a
solution.

However, I've also found a solution for doing this on
NT without (a) using polling, or (b) installing WMI
classes.  Yep, the answer was right there in the
API...

Harlan

--- Tobias Martinsson <[EMAIL PROTECTED]> wrote:
> > I'm trying to write a script that will watch the
> > EventLogs for changes (Win32::ChangeNotify doesn't
> > seem to do it).  I found some code (below) that is
> > written in WMI/WSH...but I'm having trouble
> > translating it.
> >
> > I'd appreciate any assistance.  Even a reference
> to a
> > site or book where I can learn more about
> translating
> > VBScript/WSH into Perl...
> 
> Just wrote a book on it. But for SQL Server 2000.
> (Scripting XML and WMI for
> Microsoft SQL Server 2000) And it won't come out
> until next year, so here's
> some code from it. Couldn't do much about the font
> here in Outlok Express.
> Just modify it to not check specifically for for SQL
> Server:
> 
> # ===== Import Modules and Stuff =====
> use strict;
> 
> use Win32;
> 
> use Win32::OLE qw(in);
> 
> Win32::OLE->Option("Warn"=>3);
> 
> # ================================
> 
> # Build WQL query
> 
> my $query = "SELECT * FROM __InstanceCreationEvent "
> .
> 
> "WHERE TargetInstance ISA 'Win32_NTLogEvent' " .
> 
> "AND TargetInstance.SourceName = 'MSSQLSERVER'";
> 
> # Get Locator
> 
> my $wbemloc = new
> Win32::OLE("WbemScripting.SWbemLocator");
> 
> 
> # Add Privileges for reading the Security-log
> 
>
$wbemloc->{Security_}->{Privileges}->AddAsString("SeSecurityPrivilege");
> 
> # Get Services
> 
> my $wbemsvc = $wbemloc->ConnectServer(".",
> "root/cimv2");
> 
> # Set impersonationlevel
> 
> $wbemsvc->{Security_}->{ImpersonationLevel} = 3;
> 
> # Get EventSource
> 
> my $wbemevtsrc =
> $wbemsvc->ExecNotificationQuery($query);
> 
> # while(1) begins an infinite loop
> 
> while (1) {
> 
> # Get the next event when it arrive
> 
> my $wbemobj = $wbemevtsrc->NextEvent();
> 
> # Print the message
> 
>
Win32::MsgBox($wbemobj->{TargetInstance}->{Message});
> 
> }
> 
> 
> 
> Without checking the security log:
> 
> 
> 
> # ===== Import Modules and Stuff =====
> 
> use strict;
> 
> use Win32;
> 
> use Win32::OLE qw(in);
> 
> Win32::OLE->Option("Warn"=>3);
> 
> # ================================
> 
> 
> 
> # Build WQL query
> 
> my $query = "SELECT * FROM __InstanceCreationEvent "
> .
> 
> "WHERE TargetInstance ISA 'Win32_NTLogEvent' " .
> 
> "AND TargetInstance.SourceName = 'MSSQLSERVER'" .
> 
> "AND TargetInstance.LogFile = 'Application'";
> 
> # Get Locator
> 
> my $wbemloc = new
> Win32::OLE('WbemScripting.SWbemLocator');
> 
> 
> # Get Services
> 
> my $wbemsvc = $wbemloc->ConnectServer(".",
> "root/cimv2");
> 
> # Set impersonationlevel
> 
> $wbemsvc->{Security_}->{ImpersonationLevel} = 3;
> 
> # Get EventSource
> 
> my $wbemevtsrc =
> $wbemsvc->ExecNotificationQuery($query);
> 
> # while(1) begins an infinite loop
> 
> while (1) {
> 
> # Get the next event when it arrive
> 
> my $wbemobj = $wbemevtsrc->NextEvent();
> 
> # Print the message
> 
>
Win32::MsgBox($wbemobj->{TargetInstance}->{Message});
> 
> }
> 
> 
> 
> Without using NextEvent:
> 
> package myEvents;
> 
> use Win32;
> 
> use Win32::OLE qw(in);
> 
> sub OnObjectReady {
> 
> Win32::MsgBox("Hello From OnObjectReady!");
> 
> }
> 
> sub OnCompleted {
> 
> Win32::MsgBox("Hello From OnCompleted!");
> 
> }
> 
> sub OnObjectPut {
> 
> Win32::MsgBox("Hello From OnObjectPut!");
> 
> }
> 
> sub OnProgress {
> 
> Win32::MsgBox("Hello From OnProgress!");
> 
> }
> 
> 1;
> 
> use strict;
> 
> use Win32;
> 
> use Win32::OLE qw(in EVENTS);
> 
> Win32::OLE->Option("Warn"=>3);
> 
> my $wbemsink = new
> Win32::OLE("WbemScripting.SWbemSink");
> 
> my $wbemloc = new
> Win32::OLE("WbemScripting.SWbemLocator");
> 
> my $wbemsvc = $wbemloc->ConnectServer(".",
> "root/MicrosoftSQLServer");
> 
> # Set impersonationlevel
> 
> $wbemsvc->{Security_}->{ImpersonationLevel} = 3;
> 
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to