This is driving me nuts! Is there anyone on the entire planet
who has ever actually used Microsoft's WMI ODBC Adapter,
via perl or otherwise ?!
I am trying to write a perl script to read WMI class instances
via ODBC, in the hope of producing an OS-independent script [*]
that can be run from either Windows or Unix, and ODBC seemed
to be the simplest way to go (although Microsoft's WMI ODBC
Adapter has various limitations, including being read-only).
[*] If anyone knows some way (ideally simple, but anything
considered!) to make a perl script running on Unix an OLE
client so I could use something like Win32::OLE, that would
be an alternative solution - I'm going _right_ off the idea
of using ODBC!!
Anyway, the following is a preliminary perl script I knocked
up to try and retrieve objects (ODBC 'records') of class
Win32_LogicalDisk.
But when I run the script (having installed the latest version
of wbemdr32.dll, which is effectively the WMI/WBEM ODBC Adapter)
the SQL prepare fails with the following error:
DBD::ODBC::db prepare failed:
[Microsoft][WBEM ODBC Driver][ISAM]Table does not exist
(SQL-42S00)(DBD: st_prepare/SQLPrepare err=-1) at test.pl line 23.
I think somewhere along the line one has to incorporate the WMI
"path" of "winmgmts://./root/cimv2". But that's another bridge
I have to cross.
Also, to access WMI system classes, the connection string has
to incorporate "SYSPROPS=TRUE" somehow, and I'd be interested
to know the syntax for that.
This is the test script so far:
# test.pl
#
use strict;
use warnings;
use DBI qw (:sql_types);
my $db_name = "ODBC:conn_WMI";
my $db_user = "";
my $db_pass = "";
my $db_hdl =
DBI->connect ("dbi:$db_name", $db_user, $db_pass,
{PrintError => 0, RaiseError => 1} )
or die
("DBI->connect ('dbi:$db_name', '$db_user', '$db_pass')" .
" failed: $DBI::errstr");
my $tbl_name = "winmgmts://./root/cimv2/Win32_LogicalDisk";
my $sth_sel = $db_hdl->prepare ( <<XXX );
SELECT *
FROM $tbl_name
XXX
if ($sth_sel->execute () == 0)
{
die "WMI Win32_LogicalDisk table is empty!";
}
# Hack for initial test - just return number of columns
# in the table
#
my $n_col = 0;
while (my $row = $sth_sel->fetchrow_arrayref ())
{
$n_col++;
}
print "No of columns in table = '$n_col'\n";
John Ramsden
Sagitta - Contract Developer
Tel: +44 (0)23 9244 5000
Mob: n/a
Fax: +44 (0)23 9249 8853
Web: www.sagitta-ps.com
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs