Hey i fixed it, well after fighting through a problem
Win32::OLE(0.1712) error 0x80010105: "The server threw an exception"
in METHOD/PROPERTYGET "GetOwner" at wmi-dbi.pl line 65.
seems GetOwner wont work on certain rows, so they dont return a user line
This is the same as above with the addition of the sub owner_method and its call, i wasnt sure what to say to fix the above post ...
use strict;
use warnings;
use DBI;
use DBD::WMI qw/connect prepare execute fetchrow/;
use Win32::OLE qw/in/;
#http://stackoverflow.com/questions/14257565/how-to-find-a-process-of-
+the-current-user-in-perl-using-wmi
# needs DBD::WMI
# http://search.cpan.org/~corion/DBD-WMI-0.07/lib/DBD/WMI.pm
# corion@cpan.org http://www.perlmonks.org/?node_id=5348
# http://www.perlmonks.org/?node_id=565819
#clues from
# http://www.perlmonks.org/?node_id=821593
# https://gist.github.com/aero/1260973/6efbe8684aa54c8aecb73f601e511a5
+3bfb5c6b1
# https://msdn.microsoft.com/en-us/library/aa394388(v=vs.85).aspx
# https://msdn.microsoft.com/en-us/library/aa394084(v=vs.85).aspx
my $dbh = DBI->connect('dbi:WMI:');
sub do_table{
my @tables=@_;
table: for my $table (@tables){
my $sth = $dbh->prepare('SELECT * FROM '.$table); # Win32_SerialPo
+rt
unless ($sth->execute()) { print 'Unable to select from:'.$table."
+\n"; next table;}
print 'Table:'.$table."\n";
my $rowct=0;
while (my( $row ) = $sth->fetchrow) {
print ' row:'.$rowct++."\n";
foreach my $object ( in($row->{Properties_}) ) {
my $outline=" $object->{Name} = ";
if ( ref($object->{Value}) eq "ARRAY") {
$outline.="{ ";
foreach my $value ( in($object->{Value}) ) {$outline.="$va
+lue ";}
$outline.="}";
} else {
$outline.=($object->{Value} // "");
}
print $outline."\n";
} # $object
owner_method($row);
} # thing
} # table
} # do_table
do_table("Win32_Process");
exit;
sub owner_method {
#http://stackoverflow.com/questions/14257565/how-to-find-a-proce
+ss-of-the-current-user-in-perl-using-wmi
use Win32::OLE::Variant;
my $row=shift;
### important getowner can return an fatal error otherwise
local $Win32::OLE::Warn=0;
### important getowner can return an fatal error otherwise
foreach my $object ( in($row->{Methods_}) ) {
if ($object->{Name} eq 'GetOwner') {
my $useridval;
my ($strUser, $strDomain) = ( Variant(VT_BSTR|VT_BYREF,
+''), Variant(VT_BSTR|VT_BYREF, '') );
my $name=$object->{Name};
$useridval = $row->GetOwner($strUser, $strDomain);
if (defined($useridval) && length($useridval) > 0) {
if ($useridval == 0 ){
print ' GetOwner->User = ' . $strDomain->Value.'\
+\'.$strUser->Value . "\n";
}
}
}
} # method
} # owner_method
do_table("Win32_LogonSession");
do_table("Win32_Useraccount");
#do_table("Win32_SessionDirectorySession");
#do_table("Win32_SessionDirectorySessionEx");
do_table("Win32_ComputerSystem");
do_table("Win32_Process");
do_table("Win32_OperatingSystem");
do_table("Win32_ComputerSystem");
do_table("Win32_DiskPartition");
do_table("Win32_Property");
do_table("Win32_POTSModem");
do_table("Win32_SystemBIOS");
do_table("Win32_MemoryArray");
do_table("Win32_DeviceSettings");
do_table("Win32_LogicalDisk");
do_table("Win32_PhysicalMedia");
do_table("Win32_Account");
do_table("Win32_Perf WHERE Name = 'PERL'");
do_table("Win32_NetworkAdapter");
do_table("Win32_Perf");
do_table('Win32_SerialPort');
do_table("Win32_Win32_NetworkConnection WHERE ConnectionState != 'Conn
+ected'");
do_table(qw/Win32_SerialPort
Win32_TemperatureInfo
Win32_LogonSession
Win32_NetworkAdapterConfiguration
Win32_Win32_NetworkConnection
Win32_Processor
Win32_Fan
Win32_BaseBoard
Win32_BIOS
Win32_Bus
Win32_DesktopMonitor
Win32_Desktop
Win32_Share
/);
Can you tell ive been having some fun with corion's module?
|