Title: WMI, Win32_TCPIPPrinterPort, & CGI

        I am in need of some help.  I have floundered with some help from coworkers to get this far, but we have hit a wall.  I am using WMI to collect some printer information from a workstation.  I am planning on doing this through a web page.  The issue I am having is that the HostAddress property from Win32_TCPIPPrinterPort returns the correct information when I run the script from the command line, but when I run it though IE it doesn't return anything.  I have included the script below.  If you save it as say script1.pl then you should run it like so "Script1.pl Script=Lookup PC=<ComputerName>" from a command line or "http://localhost/Script.pl?Script=Lookup&PC=<ComputerName>".  I really need this information to make this script complete its final function.  So all help is appreciated.


use CGI qw(:all);
use Win32;
use Win32::OLE;
use Win32::OLE::Variant;
my $Cgi=new CGI;
($Path,$Prog)=$0=~m!^(.*)\\(.*)!;
@VarNames=$Cgi->param();
# Create a hash with all the parameters
foreach $VarName (@VarNames)
{
        $Params{$VarName}=$Cgi->param($VarName);
}
print $Cgi->header;
print $Cgi->start_html;
foreach $Key (keys %Params)
{
        print "$Key=$Params{$Key}<br>"
}
SWITCH: {
        if ( $Params{Script} eq "Lookup") {
          &Lookup;
          last SWITCH }
        if ( $Params{Script} eq "Create Printer") {
          &Create;
          last SWITCH }
        if ( $Params{Page} eq "Title") {
          &Title;
          last SWITCH }
        if ( $Params{Script} eq "CPU") {
          &CPU;
          last SWITCH }
}
print $Cgi->end_html;
sub Lookup
{
        &Ident("Printers");
        my $CLASS = "WinMgmts:{impersonationLevel=impersonate}!//$Params{PC}";
        my $WMI = Win32::OLE->GetObject($CLASS) || die print "Error";
        $PrinterList = $WMI->InstancesOf("Win32_Printer");
        @list2 = Win32::OLE::Enum->All($PrinterList);
        print "<B>Printers Defined on $Params{PC}</B><BR>\n";
        foreach $Printer (@list2)
        {
                if ($Printer->{Network} == 0 && $Printer->{PortName} ne "LPT1:")
                {
                        print "<b>Printer:</b> $Printer->{Name}\n<BR><B>Port:</B> $Printer->{PortName}<BR>";
                }
        }
        $PortList = $WMI->InstancesOf("Win32_TCPIPPrinterPort");
        print "<BR><B>Ports Defined on $Params{PC}</B><BR>\n";
        Win32::OLE::Enum->Reset();
        @list3 = Win32::OLE::Enum->All($PortList);
        foreach $Port (@list3)
        {
                print "<B>Port Name:</B> $Port->{Name}<BR>\n<B>IP Address:</B> $Port->{HostAddress}<BR>\n";
        }
        print $Cgi->start_form(
                -method=>"POST",
                -action=>$Prog);
        print $Cgi->hidden('PC','$Params{PC}');
        print "\n<CENTER>\n";
        print $Cgi->textfield('Printer');
        print "<BR>Printer Name<BR><BR>";
        print $Cgi->textfield('IP');
        print "<BR>IP Address<BR><BR>\n";
        # A submit button
        print submit(-name=>'Script', -value=>'Create Printer');
        print "\n</CENTER>\n";
        $Cgi->delete_all();
        print $Cgi->endform;
}
sub Create
{
        &Ident("Create");
}
sub CPU
{
        &Ident("Computer");
}
sub Title
{
        print "<B> <sp> <font size=\"5\">";
        print "<CENTER> <U> Remote Computer Printer Creation</U> <small> <sp></B><FONT SIZE=\"2\" >";
        print "</underline></font>";
}
sub Ident
{
   $Message=shift;
   print "<u><b>",$Cgi->p({-align=>"CENTER"},"$Message" ),"</u></b>\n ";
        return 1
}


Kevin Ireland
Sr. Systems Engineer
Gentiva Health Services
(913) 814-2169
[EMAIL PROTECTED]


Reply via email to