For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > March 2008 > Win32::OLE different connections methods produce different results









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Win32::OLE different connections methods produce different results
HmJ

2008-03-28, 7:16 pm

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_TerminalSe
rvices", "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_TerminalSe
rvices", "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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com