"Lynn. Rickards" <[EMAIL PROTECTED]> wrote on 03/09/2006 07:33:12 PM:

> Lynn. Rickards wrote:
> > [EMAIL PROTECTED] wrote:
> > 
> > < original message removed for brevity >
> > < original reply removed for brevity >
> >  - Lynn.
> < part of reply removed for brevity >
> ...just seems to run forever until I guess Excel runs out of patience
> and craps out. Some error-checking might be in order in the loop.
> 
> HTH - Lynn.
Lynn et al-

I had the following errors:
E:\lab reports\test35>cataloge.bat

E:\lab reports\test35>rem this batch is for cataloguing computers using 
two other "helpers"

E:\lab reports\test35>rem "helpers" are psinfo and compinfo

E:\lab reports\test35>rem information section is over, turning echo off.
Win32::OLE(0.1403) error 0x8001010a: "The message filter indicated that 
the
application is busy"
    in METHOD/PROPERTYGET "Cells" at compinfo.pl line 276
Win32::OLE(0.1403) error 0x8001010a: "The message filter indicated that 
the
application is busy"
    in PROPERTYPUT "Visible" at compinfo.pl line 155

E:\lab reports\test35>

----end errors----
note: batch file merely calls perl twice in order to get all the 
computers.

my code is as follows (rep is a sub routine that prints to screen and a 
log file, along with everything before the OLE use, removed for brevity. 
full code in attached pl)

thanx in advance,
Josh

---code follows---
#! /usr/bin/perl
use strict;
use warnings;
use Getopt::Long; # used in getting unix-style options
use Win32::OLE qw(in with); # use base OLE
use Win32::OLE::Const 'Microsoft Excel'; # use OLE/Excel
   $Win32::OLE::Warn = 3; # die on errors...
use Win32::OLE::Enum;
use Win32::OLE::Variant;

# code lines removed for brevity

# set up OLE interaction
# get an active Excel or create a new one
my $Excel = Win32::OLE -> GetActiveObject('Excel.Application')
  || Win32::OLE -> new('Excel.Application', 'Quit');
$Excel -> {'Visible'} = 1;

my $labrep=`cd`;
chomp($labrep);
if (substr($labrep, -1) ne '\\'){ $labrep.='/'; }
$labrep.="Lab_Report_$date.xls";

# does the file exit?
if(-e "$labrep"){
  #we are just adding to it, so open it
  my $report = $Excel->Workbooks->Open("$labrep");
  my $ws = $report->Worksheets(1);

  # start row counter
  my $row=2;
  # set row counter to continue at the end of what's there
  my $ncell = $ws -> Range("A$row") -> {'Value'};
  while($ncell =~ m/\w+/i){
    $row++; # increment row & V- grab next row's data -V
    $ncell = $ws -> Range("A$row") -> {'Value'};
  }

  # we need to get the information & parse it into the excel file for each 
node
  foreach my $node (@comps){
    # for each node we check the information returned
    my $ldate = localtime();
    &rep("Examining information gathered from node $node @ $ldate\n", 
$verb);

    # a sub routine defined later in the script is used for simplicity
    &populate($node,$row,$ws);

    # end the loop increasing the row number
    $row++;
  }
}else{
  # we have to create it, including make the first row
  $Excel -> { 'SheetsInNewWorkBook' } = 1;
  my $workbook = $Excel -> Workbooks -> Add();
  my $ws = $workbook -> Worksheets(1);
  $ws -> { 'Name' } = "Lab Report $date";

  # set first row titles
  $ws -> Cells(1, "A") -> {'Value'} = "Node";
  $ws -> Cells(1, "B") -> {'Value'} = "NAV";
  $ws -> Cells(1, "C") -> {'Value'} = "Alarms";
  $ws -> Cells(1, "D") -> {'Value'} = "SNMP";
  $ws -> Cells(1, "E") -> {'Value'} = "Uptime";
  $ws -> Cells(1, "F") -> {'Value'} = "Kernel Version";
  $ws -> Cells(1, "G") -> {'Value'} = "Product Type";
  $ws -> Cells(1, "H") -> {'Value'} = "Product Version";
  $ws -> Cells(1, "I") -> {'Value'} = "Service Pack";
  $ws -> Cells(1, "J") -> {'Value'} = "Kernel Build Number";
  $ws -> Cells(1, "K") -> {'Value'} = "Registered Organization";
  $ws -> Cells(1, "L") -> {'Value'} = "Registered Owner";
  $ws -> Cells(1, "M") -> {'Value'} = "Install Date";
  $ws -> Cells(1, "N") -> {'Value'} = "Activation Status";
  $ws -> Cells(1, "O") -> {'Value'} = "IE Version";
  $ws -> Cells(1, "P") -> {'Value'} = "System Root";
  $ws -> Cells(1, "Q") -> {'Value'} = "Processors";
  $ws -> Cells(1, "R") -> {'Value'} = "Processor Speed";
  $ws -> Cells(1, "S") -> {'Value'} = "Processor Type";
  $ws -> Cells(1, "T") -> {'Value'} = "Physical Memory";
  $ws -> Cells(1, "U") -> {'Value'} = "Installed OS Hotfixes";
  $ws -> Cells(1, "V") -> {'Value'} = "Other Applications";

  # start row counter
  my $row=2;

  foreach my $node (@comps){
    # for each node we check the information returned
    my $ldate = localtime();
    &rep("Examining information gathered from node $node @ $ldate\n", 
$verb);

    # a sub routine defined later in the script is used for simplicity
    &populate($node,$row,$ws);

    # end the loop increasing the row number
    $row++;
  }

  $workbook -> SaveAs($labrep); # save active sheet
}

# save and exit
$Excel -> Workbooks -> Save(); # save file
$Excel -> Workbooks -> Quit(); # leave excel
my $et=locatime();
&rep("program completed at $et.",$verb); # wrap up log
close LOG; # close log

sub populate{
  # this is a subroutine to populate cells in a microsoft excel 
spreadsheet
  # this particular one is made for the compinfo.pl script/executable but 
should
  # be easily modified for other scripts, this routine does ONE row at a 
time

  my $node=$_[0]; # node who's info sheet needs to be picked apart
  my $row=$_[1]; # row to add info too
  my $ws=$_[2]; # worksheet link
  my $err=0; # error marker

  # this expects the following row set up:
  # A -> Node; B -> NAV; C -> Alarms; D -> SNMP; E -> Uptime;
  # F -> Kernel Version; G -> Product Type; H -> Product Version;
  # I -> Service Pack; J -> Kernel Build Number; K -> Registered 
Organization;
  # L -> Registered Owner; M -> Install Date; N -> Activation Status;
  # O -> IE Version; P -> System Root; Q -> Processors; R -> Processor 
Speed;
  # S -> Processor Type; T -> Physical Memory; U -> Installed OS Hotfixes;
  # V -> Other Applications;

  # set the first cell since that's always going to be the same
  $ws -> Cells($row, "A") -> {'Value'} = "$node";

  my $cmd = "psinfo -h -s \\\\$node";
  my @examine = split "\n", `$cmd`;

  # noting which couldnt be connected to...
  if($examine[6] =~ m/The network path was not found./i ){
    $ws -> Cells($row, "B") -> {'Value'} = "The network path was not 
found.";

  }else{
    # we need to run through the information to put into the rows
    # drop what's before what we need
    while (!($examine[0] =~ m/Uptime.*/i)){ shift(@examine); }

    while (!($examine[0] =~ m/OS Hot Fix.*/i)){
      # now go through a series of if/elsif sections for the rest
      # hot fixes and programs will be handled slightly differently though

      if($examine[0] =~ m/Uptime:\s+(\w.*)/i){
        $ws -> Cells($row, "E") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Kernel version:\s+(\w.*)/i){
        $ws -> Cells($row, "F") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Product type:\s+(\w.*)/i){
        $ws -> Cells($row, "G") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Product version:\s+(\w.*)/i){
        $ws -> Cells($row, "H") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Service pack:\s+(\w.*)/i){
        $ws -> Cells($row, "I") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Kernel build number:\s+(\w.*)/i){
        $ws -> Cells($row, "J") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Registered organization:\s+(\w.*)/i){
        $ws -> Cells($row, "K") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Registered owner:\s+(\w.*)/i){
        $ws -> Cells($row, "L") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Install date:\s+(\w.*)/i){
        $ws -> Cells($row, "M") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Activation status:\s+(\w.*)/i){
        $ws -> Cells($row, "N") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/IE version:\s+(\w.*)/i){
        $ws -> Cells($row, "O") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/System root:\s+(\w.*)/i){
        $ws -> Cells($row, "P") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Processors:\s+(\w.*)/i){
        $ws -> Cells($row, "Q") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Processor speed:\s+(\w.*)/i){
        $ws -> Cells($row, "R") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Processor type:\s+(\w.*)/i){
        $ws -> Cells($row, "S") -> {'Value'} = "$1";
      }elsif($examine[0] =~ m/Physical memory:\s+(\w.*)/i){
        $ws -> Cells($row, "T") -> {'Value'} = "$1";
      }
    }

    #  remove the line starting "OS Hot Fix..."
    shift(@examine);
    # create a variable for holding the hotfixes
    my $hotfixes="\"";

    while (!($examine[0] =~ m/Applications.*/i)){
      # while hot fixes need to be added. skip blank lines
      if($examine[0] =~ m/\w/){
        chomp($examine[0]);
        $hotfixes .="$examine[0]\n";
      }
    }

    # add the hotfixes
    $ws -> Cells($row, "U") -> {'Value'} = "$hotfixes";

    #  remove the line starting "Applications..."
    shift(@examine);

    my $apps='';
    foreach my $app (@examine){
      # the rest should all be applications to add so we're using a 
foreach to
      # put them in; only add lines that are not blank; there are 3 
special
      # lines: NAV, Alarms, and SNMP
      if($app =~ m/Symantec AntiVirus (\w+)/i){
        $ws -> Cells($row, "B") -> {'Value'} = "ver: $1";
      }elsif($app =~ m/Alarm/i){
        $ws -> Cells($row, "C") -> {'Value'} = "Installed";
      }elsif($app =~ m/SNMP Informant Agent \(([^\)]+)\) (\w.*)/i){
        $ws -> Cells($row, "D") -> {'Value'} = "$1 : $2";
      }elsif($app =~ m/\s+(\w.*)/i){
        $apps .= "$1\n";
      }
    }

    # add the other applications
    $ws -> Cells($row, "V") -> {'Value'} = "$apps";
  }
}
################################################################################
__END__




-----------------------------------------
PLEASE NOTE: 
SeaChange International headquarters in Maynard, MA is moving!
Effective March 1, 2006, our new headquarters address will be:

SeaChange International 
50 Nagog Park 
Acton, MA 01720 USA 

All telephone numbers remain the same: 
Main Corporate Telephone: 978-897-0100 
Customer Service Telephone: 978-897-7300

Attachment: compinfo.pl
Description: Binary data

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to