Hello,
I work at the helpdesk for my college, and one of my tasks is to count the
number of logged-in students in each lab at the top of every hour.  I realized
that this is the perfect place for automation using a script, and I started
learning PERL in order to do something along these lines.  However, I'm having
some issues with them, and I would be very greatful if you could help me out.

I have written two scripts: one server and one client.

The server script is heavily dependant on the basic remote process example that I 
found on your mailing list.  Here it is:
----------------------------------------------------
#! c:/perl/bin/perl.exe -I //ykdgiga-106-hd/lib

################################################
#HeadCountv2.pl By Daniel Skiles
#This script counts heads just like the old one,
#only now it's full of server-y goodness.
#The majority of this code came from the ASPN
#mailing list (aspn.activestate.com)
################################################

use Win32::GUI;
use Win32::OLE qw(in with);
use Win32::OLE::Variant;

$window = GUI::GetPerlWindow();
GUI::Hide($window);

##NIFTY VARIABLES##
$host = shift || die "No hostname entered";
$task = "c:/perl/bin/perl.exe //ykdgiga-106-hd/someTypeOfShare/headCountClient.pl";

$CLASS = "WinMgmts:{impersonationLevel=impersonate}!//$host" ||
die "WinMgmts issues";

$WMI = Win32::OLE->GetObject($CLASS) or die '$WMI problems' ||
die "GetObject Issues";

$Process = $WMI->Get("Win32_Process") or die 'Process troubles';
-------------------------------------------------------------

When run as an admin this will remotely start a process on a machine.  It seems to 
work just fine when I test it with things like notepad and cmd.exe.  However,
when I set it to run my client script it completely freaks out.

This is my client script:
------------------------------------------------------------
#! c:/perl/bin/perl.exe #-I //ykdgiga-106-hd/lib

#Headcount script by Daniel Skiles (Client side information gatherer)
#Use this module to keep things on the level (when debugging)
#The Hostname module is used instead of backticks to keep things clean
#GUI is used to hide the window
#       use warnings;
use Sys::Hostname;
use Win32::GUI;

#Hides the window from the user
$window = GUI::GetPerlWindow();
GUI::Hide($window);


#Get the name for the file, based on the local time
#Substitutes colons for slashes, and underscores for spaces
#It then chops it up a bit to get rid of the extraneous information.
                $fileName = localtime();
                $fileName =~ s/:/-/g;
                $fileName = '//ykdgiga-106-hd/someTypeOfShare/' . $fileName;

                for($i=0; $i < 11; $i++)
                {
                        chop($fileName);
                }

                $fileName =~ s/ /_/g;
                $fileName = $fileName . ".txt";

        #Get's the user's name
                $userID = `whoami`;

        #Gets the hostname
                $host = hostname();

        #Removes the newline from each of these variables
                chomp($userID);
                chomp($host);

        #Yes, this should be a batch file, but it isn't.
        #Opens a file and adds the pertinent information,
        #unless the file doesn't exist yet, and then it makes it
                open(FILE, ">> $fileName");
                
                for($i=0; $i<500; $i++)
                {
                        if($userID)
                        {
                                print FILE $host, " ", $userID, "\n";
                                $userID = "";
                        }
                }
--------------------------------------------------------------
I'm going to guess you all can tell that most of my programming experience is in c++ 
:).  This script runs perfectly too.  However, it doesn't do it's assigned
task when run as a remote process.  I'd like to read what's in the box that
pops up on the remote machine, but even if I disable the window-hide it
terminates too fast for me to read.  Do any of you see any issues with my code?
 This is an all Win2000 environment using the latest build of activeState perl.

Thank you for you help


_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to