Win32::OLE different connections methods produce different results

Discussion in 'Perl Misc' started by HmJ, Mar 28, 2008.

  1. HmJ

    HmJ Guest

    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
    HmJ, Mar 28, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick.O.Ige

    Ole ole

    Patrick.O.Ige, Jul 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    488
    Patrick.O.Ige
    Jul 16, 2006
  2. Replies:
    5
    Views:
    462
    Luc The Perverse
    Oct 27, 2006
  3. Benman
    Replies:
    0
    Views:
    124
    Benman
    Dec 9, 2005
  4. Lance Hoffmeyer
    Replies:
    0
    Views:
    238
    Lance Hoffmeyer
    Nov 17, 2003
  5. Daniel Berger

    Win32::OLE, WMI and executing methods

    Daniel Berger, Jun 3, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    481
    Daniel Berger
    Jun 4, 2004
Loading...

Share This Page