habshi has asked for the wisdom of the Perl Monks concerning the following question:
here is output from windows:use warnings ; use strict ; use Data::Dumper ; use DBI; my $disk_status = 0; my $dbh = DBI->connect('dbi:WMI:11.0.0.1'); my $sessions = $dbh->prepare("SELECT * FROM Win32_LogonSession WHERE L +ogonType<>3 AND LogonType<>5 AND LogonType<>0 AND LogonType<>8 AND Lo +gonType<>9 AND LogonType<>4") or die "Failed get sessions object\n"; $sessions->execute(); while (my @session_row = $sessions->fetchrow) { my $live_session = 0; my $disk_flag = 0; my $session = $session_row[0]; my $session_id = $session->{LogonId}; my $processes = $dbh->prepare("Associators of {Win32_LogonSession. +LogonId=".$session_id."} Where AssocClass=Win32_SessionProcess Role=A +ntecedent") or die "Failed get process object\n"; $processes->execute(); while (my @process_row = $processes->fetchrow) { my $process = $process_row[0]; my $process_name = $process->{Caption}; if ($process_name =~ /^explorer.exe$/) { $live_session = 1; } } next if (!$live_session); my $users = $dbh->prepare("Associators of {Win32_LogonSession.Logo +nId=".$session_id."} Where AssocClass=Win32_LoggedOnUser Role=Depende +nt") or die "Failed get users object\n"; $users->execute(); while (my @user_row = $users->fetchrow) { my $user = $user_row[0]; my $user_name = $user->{Name}; my $mapped_disks = $dbh->prepare("Associators of {Win32_LogonS +ession.LogonId=".$session_id."} Where AssocClass=Win32_LogonSessionMa +ppedDisk Role=Antecedent") or die "Failed get mapped disks object\n"; $mapped_disks->execute(); while (my @mapped_disks_row = $mapped_disks->fetchrow) { my $mapped_disk = $mapped_disks_row[0]; my $disk_uri = $mapped_disk->{ProviderName}; if ($disk_uri =~ /\\\\storage\\shared/) { $disk_flag = 1; } } } if ($disk_flag == 1) { print $user_name." has mapped drive\n"; } else { print $user_name." has no mapped drive\n"; } $disk_flag = 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: nrpe + wmi problem
by roboticus (Chancellor) on Jun 19, 2011 at 14:56 UTC | |
by habshi (Initiate) on Jun 20, 2011 at 13:09 UTC |