Actually, my tests were done on Windows XP SP2.

________________________________________
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of D D Allen
Sent: Friday, May 12, 2006 4:41 AM
To: Jan Dubois
Cc: [email protected]
Subject: RE: "WbemScripting.SWbemRefresher" VBScript -> Perl


Thank you for your response.   This gives me a way to continue developing this 
script. 

I'm running Windows XP SP1 (all security patches applied) and AS Perl 5.8.8 
build 817.... and WSH 5.6. 

Concerning the responses from Timothy Johnson and Chris Wagner, both of whom I 
believe are running Windows 2000, the MSDN page on WMI "Scripting API Objects" 
indicates that the SWbemRefresher class / object is not available for Windows 
2000 and all prior Windows versions.  So it's only available in Win XP, Win 
2003, Vista, ... 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/scripting_api_objects.asp
 


But "[EMAIL PROTECTED]" was able to run this as a native perl script... so he 
may hold the answer to the riddle. 

Regards,

... Dewey


"Jan Dubois" <[EMAIL PROTECTED]> 
05/11/2006 11:28 PM 
To
D D Allen/Fairfax/[EMAIL PROTECTED], "'Timothy Johnson'" <[EMAIL PROTECTED]> 
cc
<[EMAIL PROTECTED]>, <[email protected]> 
Subject
RE: "WbemScripting.SWbemRefresher" VBScript -> Perl







I don't think this issue is related to the PDK, so please return further 
discussion to Perl-Win32-Users only. 
  
I have no idea what is going on, but I can reproduce the problem.  If I rename 
netmon.pls to netmon.pls and execute it via `cscript netmon.pls` then it works 
fine also. If anyone has an idea why it makes a difference to run the script 
inside Windows Scripting Host, please let me know. 
  
Cheers, 
-Jan 
  
PS:  Please use plain text for mailing list messages. 
  

________________________________________

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of D D Allen
Sent: May 11, 2006 2:37 PM
To: Timothy Johnson
Cc: [EMAIL PROTECTED]; [email protected]
Subject: RE: "WbemScripting.SWbemRefresher" VBScript -> Perl 
  

I subscribed to the PDK list... and am copying it on this note. 

I'm now suspicious that there's a "type" (object class) mismatch problem.  [Ok, 
I'm stretching for an explanation...] 

When I look at the "SwbemRefresher" class in Jan Dubois' Win32::OLE Type 
Library Browser, the AddEnum definition is as follows. 

Function AddEnum(objWbemServices As ISWbemServicesEx, bsClassName As String, 
[iFlags As Long], [objWbemNamedValueSet As Object]) As ISWbemRefreshableItem 

On MSDN, the SWbemRefresher AddEnum definition is as follows. 

objRefreshEnum = AddEnum( 
 objWbemService, 
 strClass, 
 [ iFlags = 0 ], 
 [ objWbemNamedvalueSet = null ] 
) 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/swbemrefresher_addenum.asp
 


The subtle difference is that the Type Library Browser identifies the first 
parameter as a SWbemServicesEx object -- while MSDN identifies it as a 
SWbemService object.  And on MSDN, SWbemServices and SWbemServicesEx are 
different -- with SWbemServicesEx being derived from the SWbemServices class.  
Maybe this makes a difference in Perl but not in VBScript... 


Regards,

... Dewey 

"Timothy Johnson" <[EMAIL PROTECTED]> 
05/11/2006 03:26 PM 

To
D D Allen/Fairfax/[EMAIL PROTECTED], 
<[email protected]> 
cc
  
Subject
RE: "WbemScripting.SWbemRefresher" VBScript -> Perl

  

  
 





You should submit this to the PDK list.  I've tried changing the authentication 
level, etc. but as far as I can tell your code is correct. 
 
 
  

  
________________________________________


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of D D Allen
Sent: Thursday, May 11, 2006 5:24 AM
To: [email protected]
Subject: "WbemScripting.SWbemRefresher" VBScript -> Perl 
 

I've been trying to write a Perl script that uses the WMI OLE object 
"WbemScripting.SWbemRefresher" to access TCP statistics -- using the WMI 
performance counter class "Win32_PerfFormattedData_Tcpip_NetworkInterface". 

I've got it working in VBScript "no issues".  But my Perl Win32::OLE 
translation bombs out with an "Access Denied" OLE exception from 
"SWBemRefresher" raised by the "AddEnum" call.   I use the same setup code in 
other WMI perl scripts that perform ExeQuery's -- that work. 

VBScript and perl translation follow. 

Anyone have any ideas? 

Regards,

... Dewey


============= netmon.vbs ================ 
==command line:  "cscript netmon.vbs"========= 

strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
set objRefresher = CreateObject("WbemScripting.SWbemRefresher") 
Set colItems = objRefresher.AddEnum _ 
  (objWMIService, "Win32_PerfFormattedData_Tcpip_NetworkInterface").objectSet 
objRefresher.Refresh 

For i = 1 to 50 
  For Each objItem in colItems 
          If objItem.BytesTotalPersec > 0 Then 
                  Wscript.Echo "*********" 
              Wscript.Echo "(" & i & ") Name: " & objItem.Name 
               Wscript.Echo "Total Bytes Per Second: " & _ 
                  objItem.BytesTotalPersec 
               Wscript.Echo "Bytes Sent Per Second: " & _ 
                  objItem.BytesSentPersec 
               Wscript.Echo "Bytes Received Per Second: " & _ 
                  objItem.BytesReceivedPersec 
               Wscript.Echo "Packets Per Second: " & _ 
                  objItem.PacketsPersec 
               Wscript.Echo "Packets Sent Per Second: " & _ 
                  objItem.PacketsSentPersec 
               Wscript.Echo "Packets Received Per Second: " & _ 
                  objItem.PacketsReceivedPersec 
      End If 
      objRefresher.Refresh 
  Next 
  Wscript.Sleep 2000 
Next 


============= netmon.pl ================ 
==command line:  "perl netmon.pl"========= 

use strict; 
use warnings; 

use Win32::OLE qw(in); 

$Win32::OLE::Warn = 3; 

my $strComputer = '.'; 
my $objWMIService = 
Win32::OLE->GetObject('winmgmts:{impersonationLevel=impersonate}!//' . 
$strComputer . '/root/cimv2'); 

my $objRefresher = Win32::OLE->new('WbemScripting.SWbemRefresher'); 

my $colItems = $objRefresher->AddEnum ($objWMIService, 
'Win32_PerfFormattedData_Tcpip_NetworkInterface')->ObjectSet; 

$objRefresher->Refresh; 

foreach my $i (1 .. 50) { 
  foreach my $objItem (in $colItems) { 
          if ($objItem->{BytesTotalPersec} > 0) { 
                  print "*********\n"; 
              print "($i) Name: ", $objItem->{Name}, "\n"; 
              print "Total Bytes Per Second: ", $objItem->{BytesTotalPersec}, 
"\n"; 
              print "Bytes Sent Per Second: ", $objItem->{BytesSentPersec}, 
"\n"; 
              print "Bytes Received Per Second: ", 
$objItem->{BytesReceivedPersec}, "\n"; 
              print "Packets Per Second: ", $objItem->{PacketsPersec}, "\n"; 
              print "Packets Sent Per Second: ", 
$objItem->{PacketsSentPersec},"\n"; 
              print "Packets Received Per Second: ", 
$objItem->{PacketsReceivedPersec}, "\n"; 
      } 
      $objRefresher->Refresh; 
  } 
  sleep(2); 
} 


_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to