in reply to Re^2: Perl $ENV hash
in thread Perl $ENV hash

If you want to use DBD::WMI, you have to install it. See A guide to installing modules for Win32. Alternatively, finding out whether wmic is installed on your machine is a matter of trying to run it from the command line.

Replies are listed 'Best First'.
Re^4: Perl $ENV hash
by kingjamesid (Acolyte) on Apr 20, 2010 at 19:02 UTC
    what is wrong here. nothing is printing to the file, list.txt
    #use warnings; #use DBI; use Win32; use Win32::OLE qw (in); open(HLOG,">c:/temp/logf.txt") || die " Open Log_file: $!"; open(HLIST,">C:/temp/list.txt") || die " Open list.txt: $!"; #my $dbh = DBI->connect('dbi:DBI:'); while(<>) { chomp($_); @a = `ping -n 1 $_`; print "for $_:"; if ("@a" =~ /Request timed out/i || "@a" =~ /could not find host/i + ){ print "<<<<not Alive>>>>>\n"; #TODO #spit it to non-alive txt file #close file print(HLOG); } else { print "::: Alive\n"; my $Class = "WinMgmts://$_"; my $Wmi = Win32::OLE->GetObject ($Class); if ($Wmi) { my %Vars = $Wmi->ExecQuery("SELECT * FROM $Win32_Environme +nt"); print $Vars; foreach (keys %Vars) { print HLIST $Vars{$_} ."\n"; } } else { print "NO idea"; } #TODO: if alive, check if cadmap exists, if yes, spit the var= +value pair to a log.txt file. } } close (HLOG) || die "Close: $!"; close (HLIST) || die "Close:$!";

      You are not using the strict pragma. If you had done so, Perl would have forced you to declare all variables you use. That would have shown you that there is no variable declared with the name $Win32_Environment, but you try to use it in your string.

        that was a mistake. I removed the '$'. But still didnt work I tried something else
        if ($Wmi) { my $Vars = $Wmi->Get('Win32_Environment'); my $var = $Vars->Spawninstance_ (); #print $var; print $var ->{'CADMAP'}; $var->put_(); #print HLIST $Vars{"pc_os"}; #foreach (keys %Vars) { # print HLIST $Vars{$_} ."\n"; #} }
        Still no luck.