Task is running only once!

R

RBCS

Hello

Why is in this script the runas not running twice,
once for $tasks and once for $tasksa?

I have active state Perl v5.8.7 build 815!

Roman


#!/usr/bin/perl
#############################################################################
## Name: samples/controls/controls.pl
## Purpose: Controls wxPerl sample
## Author: Mattia Barbon
## Modified by:
## Created: 29/10/2000
## RCS-ID: $Id: controls.pl,v 1.12 2004/10/19 20:28:13 mbarbon Exp $
## Copyright: (c) 2000, 2003 Mattia Barbon
## Licence: This program is free software; you can redistribute it and/or
## modify it under the same terms as Perl itself
##############################################################################
#

my $Domain = "GLION";
my $User = "banz";
my $Password = "soulman1291";
my (@tasks);
my $taski=0;

$tasks[$taski] = ( "notepad" );
$taski++;
$tasks[$taski] = ( "msiexec" );
$taski++;
$tasks[$taski] = ( "notepad" );
my $ResultofRunas = RunAs->logininfo($Domain, $User, $Password, @tasks);

my (@tasksa);
my $taskia=0;
$tasksa[$taskia] = ( "notepad" );
$taskia++;
$tasksa[$taskia] = ( "msiexec" );
$taskia++;
$tasksa[$taskia] = ( "notepad" );
$ResultofRunas = RunAs->logininfo($Domain, $User, $Password, @tasksa);
print "Result of Runas: $ResultofRunas";

package RunAs;

use Win32::AdminMisc;
use POE qw(Wheel::Run Filter::Reference);

sub logininfo{
my( undef, $Domain, $User, $Password, @Process ) = @_;

sub MAX_CONCURRENT_TASKS () { 3 }

my $Result = Win32::AdminMisc::LogonAsUser( $Domain,
$User,
$Password,
LOGON32_LOGON_INTERACTIVE );
if( $Result )
{
my $LogonUser = Win32::AdminMisc::GetLogonName();
print "Successfuly started process as $LogonUser.\n";

$Result = POE::Session->create
( inline_states =>
{ _start => \&start_tasks,
next_task => \&start_tasks,
task_result => \&handle_task_result,
task_done => \&handle_task_done,
task_debug => \&handle_task_debug,
}
);

if( $Result )
{

print "Successfuly executed!\n";
}
else
{
my $err= Error();
print"$err\n";
}
}
else
{
my $err = Error();
print"$err\n";
}

$poe_kernel->run();
my $logofresult = Win32::AdminMisc::LogoffAsUser();
print "Logging off...\n";

sub Error {
return( Win32::FormatMessage( Win32::AdminMisc::GetError() ) );
}

sub start_tasks {
my $heap = $_[HEAP];
while ( keys( %{ $heap->{task} } ) < MAX_CONCURRENT_TASKS ) {

my $next_task = shift @Process;
last unless defined $next_task;
print "Starting task for $next_task...\n";
my $task = POE::Wheel::Run->new
( Program => ["$next_task", , ],
StdoutFilter => POE::Filter::Reference->new(),
StdoutEvent => "task_result",
StderrEvent => "task_debug",
CloseEvent => "task_done",
);
$heap->{task}->{ $task->ID } = $task;
}
}

sub handle_task_result {
my $result = $_[ARG0];
print "Result for $result->{task}: $result->{status}\n";
}

sub handle_task_debug {
my $result = $_[ARG0];
print "Debug: $result\n";
}

sub handle_task_done {
my ( $kernel, $heap, $task_id ) = @_[ KERNEL, HEAP, ARG0 ];
delete $heap->{task}->{$task_id};
$kernel->yield("next_task");
}
}
 
A

A. Sinan Unur

Why is in this script the runas not running twice,
once for $tasks and once for $tasksa?

I have active state Perl v5.8.7 build 815!

Why the exclamation point?
##############################################################
# Name: samples/controls/controls.pl
# Purpose: Controls wxPerl sample
# Author: Mattia Barbon

I remember this exact same script being posted here before. It is good
that you gave credit to the original author.

On the other hand, I prefer to help people with problems they encounter
when writing their own programs, rather than fix scripts written by a
third-party so the poster can copy and paste with impunity.

That said, the program successfully opens two notepad windows and the
msiexec options dialog on my system, then proceeds to cause a GPF when
one of those is closed.

That probably has to with how POE works, and I do not know anything
about that.

Sinan
 
T

Tad McClellan

RBCS said:
my (@tasks);
$tasks[$taski] = ( "notepad" );
$taski++;
$tasks[$taski] = ( "msiexec" );
$taski++;
$tasks[$taski] = ( "notepad" );


You can replace all of those lines of code with:

my @tasks = qw/ notepad msiexec notepad /;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top