Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Win32::OLE different connections methods produce different results

Reply
Thread Tools

Win32::OLE different connections methods produce different results

 
 
HmJ
Guest
Posts: n/a
 
      03-28-2008
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Lingering Idle Oracle Connections? Persistent connections? jobs ASP .Net 2 11-16-2007 03:37 AM
Date format for ASP and SQL String Doesn't Produce Results Billy ASP General 2 01-30-2007 07:09 PM
can java produce .exe? if it can produce jar,how do you do? aungkopyay@gmail.com Java 5 10-27-2006 02:07 AM
Same ASP page executed 2 ways produce different results...strange Benman ASP General 0 12-09-2005 06:47 PM



Advertisments