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

I have been asked to convert a Windows Script File into a Perl script for someone. I don't have any WSF scripting skills & wondered if any PerlMonks out there would be kind enough to help me convert it.

Please do not vote this down if you don't like it because it is a WSF scripting question. Consider it as assisting a WSF fanatic to convert to Perl, and a small starting point for any PerlMonks who have similar problems in future!

<job> <script language="VBScript"> Dim Test # Take a look at the Running Object Table for "MMT.VideoServeAutomatio +n.1" (known as the program ID) # Return an object pointer to currently running instance of the object +. Set Test=GetObject (,"MMT.VideoServeAutomation.1") Set Vid = Test.VideoServeStatus # Take Vid object & connects it so it gets the windows event. WScript.ConnectObject Vid,"ie_" WScript.Sleep (800000) Sub ie_Connected ( number, CallerID) MsgBox "Hello" End Sub Sub ie_DisConnected ( number) MsgBox "Goodbye!" End Sub Sub ie_DTMFTone (Cardnumber,Tone) MsgBox "Tone!" End Sub </script> </job>

Replies are listed 'Best First'.
(Corion) OLE Automation with Perl even has Events
by Corion (Patriarch) on Aug 04, 2000 at 12:57 UTC

    At first I shyed away from replying with some uninformed and untested code, but seeing crazyinsomniacs short and not that accurate reply, I'll have to take a stab at this.

    Update: Research before you type. Of course, crazyinsomniac was right, but his answer was a bit too short for my taste :).

    Further update: Digging deeper through the Win32::OLE documentation, events now seem to have Alpha support. So maybe it is possible. I'll dig some more ... Yes - it looks like the code below could actually work ...

    Please do note, that your script uses many features that I am not sure Perl can use already ... I'm also not so sure about whether my code will actually work, but it will be a pointer in a direction that offers further frustration :)

    #!/usr/bin/perl -w use strict; # We'll be dealing with OLE stuff, so we need Win32::OLE use Win32::OLE qw(EVENTS); my $Test; $Test = Win32::Ole->GetActiveObject( "MMT.VideoServeAutomation.1" ); # so far so good. I'm in real doubt that Win32::OLE implements # OLE events as they aren't for the faint of heart and require # some kind of multi-threading or at least polling of a # message queue. # Reading the documentation for Win32::OLE, it clearly # states that OLE events are not supported. So crazyinsomniac # is actually quite right with his statement that it can't # be done in Perl. D'oh. # Hehe - all is not lost - Win32::OLE comes to the rescue Win32::OLE->WithEvents( $Test, \&EventHandler ); sub EventHandler { my ($Obj, $Event, @Args) = @_; print "Got event $Event\n"; # Here is some guesswork how to find out the "right" event ... if ($Event =~ /^Connected/i) { # I hate message boxes popping up ... print "Hello\n"; } elsif ($Event =~ /^DisConnected/i) { print "Goodbye\n"; } elsif ($Event =~ /DTMFTone/i ) { print "Tone :", join(" ", @Args ), "\n"; } }; # Now we got the events set up, and we only need to loop # until the user terminates our program ... # I hope that sleeping 100 ms on each turn dosen't # hit any OLE timeouts ... while (1) { sleep( 100 ); };

    This is completely untested, as I'm on a Linux machine right now. Maybe it will actually work !

(crazyinsomniac) Re: Converting a small Windows Script File to a Perl equivalent
by crazyinsomniac (Prior) on Aug 04, 2000 at 12:48 UTC
    can't be done.
     ______________________________________________
    |_____¸.·ooO--(> cRaZy is co01. <)--Ooo·.¸_____|
     ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ