Win32::OLE different connections methods produce different results

H

HmJ

Hi,
It seems what when using perl Win32::OLE for WMI queries it produces
different results depending on method used to connect to server,
examples bellow, can somebody explain this issue?


Examples

Using ConnectServer() I get
ActiveSessions: 0
TotalSessions: 0

Script
#!/usr/bin/perl

use strict;
use Win32::OLE('in');

use constant wbemFlagReturnImmediately => 0x10;
use constant wbemFlagForwardOnly => 0x20;

my $computer = "server";
my $user = 'DOMAIN\USER';
my $pwd = "password";
my $wmipath = 'root\\cimv2';

print "\n";
print "==========================================\n";
print "Computer: $computer\n";
print "==========================================\n";


my $wmiwebloc = Win32::OLE->new('WbemScripting.SWbemLocator');
my $wmi = $wmiwebloc->ConnectServer($computer,$wmipath,$user,$pwd);
$wmi->{Security_}->{ImpersonationLevel} = 3;

if (Win32::OLE::LastError()) {
print 'Authentication failed: ' . ('' . Win32::OLE::LastError()),
"\n";
}



my $colItems = $wmi->ExecQuery("SELECT * FROM
Win32_PerfRawData_TermService_TerminalServices", "WQL",
wbemFlagReturnImmediately | wbemFlagForwardOnly);

foreach my $objItem (in $colItems) {
print "ActiveSessions: $objItem->{ActiveSessions}\n";
print "Caption: $objItem->{Caption}\n";
print "Description: $objItem->{Description}\n";
print "Frequency_Object: $objItem->{Frequency_Object}\n";
print "Frequency_PerfTime: $objItem->{Frequency_PerfTime}\n";
print "Frequency_Sys100NS: $objItem->{Frequency_Sys100NS}\n";
print "InactiveSessions: $objItem->{InactiveSessions}\n";
print "Name: $objItem->{Name}\n";
print "Timestamp_Object: $objItem->{Timestamp_Object}\n";
print "Timestamp_PerfTime: $objItem->{Timestamp_PerfTime}\n";
print "Timestamp_Sys100NS: $objItem->{Timestamp_Sys100NS}\n";
print "TotalSessions: $objItem->{TotalSessions}\n";
print "\n";

}


Output
==========================================
Computer: server
==========================================
ActiveSessions: 0
Caption:
Description:
Frequency_Object: 10000000
Frequency_PerfTime: 2605950000
Frequency_Sys100NS: 10000000
InactiveSessions: 0
Name:
Timestamp_Object: 128511849607031250
Timestamp_PerfTime: 5097696116216139
Timestamp_Sys100NS: 18446742399360059616
TotalSessions: 0



While Using Win32::OLE->GetObject I get
ActiveSessions: 1
TotalSessions: 2

Script
#!/usr/bin/perl

use strict;
use Win32::OLE('in');

use constant wbemFlagReturnImmediately => 0x10;
use constant wbemFlagForwardOnly => 0x20;

my $computer = "server";
my $user = 'Domain\User';
my $pwd = "password";
my $wmipath = 'root\\cimv2';


print "\n";
print "==========================================\n";
print "Computer: $computer\n";
print "==========================================\n";

my $wmi = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\
\CIMV2") or die "WMI connection failed.\n";


my $colItems = $wmi->ExecQuery("SELECT * FROM
Win32_PerfRawData_TermService_TerminalServices", "WQL",
wbemFlagReturnImmediately | wbemFlagForwardOnly);

foreach my $objItem (in $colItems) {
print "ActiveSessions: $objItem->{ActiveSessions}\n";
print "Caption: $objItem->{Caption}\n";
print "Description: $objItem->{Description}\n";
print "Frequency_Object: $objItem->{Frequency_Object}\n";
print "Frequency_PerfTime: $objItem->{Frequency_PerfTime}\n";
print "Frequency_Sys100NS: $objItem->{Frequency_Sys100NS}\n";
print "InactiveSessions: $objItem->{InactiveSessions}\n";
print "Name: $objItem->{Name}\n";
print "Timestamp_Object: $objItem->{Timestamp_Object}\n";
print "Timestamp_PerfTime: $objItem->{Timestamp_PerfTime}\n";
print "Timestamp_Sys100NS: $objItem->{Timestamp_Sys100NS}\n";
print "TotalSessions: $objItem->{TotalSessions}\n";
print "\n";

}

Output
==========================================
Computer: server
==========================================
ActiveSessions: 1
Caption:
Description:
Frequency_Object: 10000000
Frequency_PerfTime: 2605950000
Frequency_Sys100NS: 10000000
InactiveSessions: 1
Name:
Timestamp_Object: 128511890915625000
Timestamp_PerfTime: 5108460132511734
Timestamp_Sys100NS: 18446742440665596616
TotalSessions: 2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top