[python-win32] Getting Network Information/Statistics

Alexander Belyaev belyaev at smartdesktop.com
Thu Jan 24 20:02:50 CET 2008


I am new to python and so far could not figure out what 'tp' means in
the following?

Thanks,
Alexander

    tp,val = win32pdh.GetFormattedCounterValue( hc,
win32pdh.PDH_FMT_LONG )
    print hex(tp),val

-----Original Message-----
From: python-win32-bounces at python.org
[mailto:python-win32-bounces at python.org] On Behalf Of
python-win32-request at python.org
Sent: Wednesday, January 23, 2008 4:05 PM
To: python-win32 at python.org
Subject: python-win32 Digest, Vol 58, Issue 38

Send python-win32 mailing list submissions to
	python-win32 at python.org

To subscribe or unsubscribe via the World Wide Web, visit
	http://mail.python.org/mailman/listinfo/python-win32
or, via email, send a message with subject or body 'help' to
	python-win32-request at python.org

You can reach the person managing the list at
	python-win32-owner at python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of python-win32 digest..."


Today's Topics:

   1. python layoutdialog (kNish)
   2. Re: Creating a process and getting a handle (Mike Driscoll)
   3. Re: Creating a process and getting a handle (Mike Driscoll)
   4. Re: Creating a process and getting a handle (Mike Driscoll)
   5. Re: Getting Network Information/Statistics (Tim Roberts)
   6. Re: Export emails from msoutlook to my local	directory
      (Tim Roberts)
   7. Re: python layoutdialog (Tim Roberts)
   8. Re: Getting Network Information/Statistics (>.>)


----------------------------------------------------------------------

Message: 1
Date: Wed, 23 Jan 2008 16:31:45 +0530
From: kNish <singhai.nish at gmail.com>
Subject: [python-win32] python layoutdialog
To: python-win32 at python.org
Message-ID:
	<81bfef2e0801230301x94bc2e2vbe4329e9557cd6cc at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi,

        Maya python command layoutDialog, in my view works strange. It
takes the procedure from MEL equivalent if exists else gives an error.
How may I successfully execute a layoutDialog in python in maya.


BRgds,

kNish


------------------------------

Message: 2
Date: Wed, 23 Jan 2008 09:19:53 -0600 (CST)
From: "Mike Driscoll" <mdriscoll at co.marshall.ia.us>
Subject: Re: [python-win32] Creating a process and getting a handle
To: <python-win32 at python.org>
Message-ID: <003001c85dd3$59f6faa0$96c051d8 at mcis0492>
Content-Type: text/plain;	charset="us-ascii"

Tim, 

Mike Driscoll wrote:
> > I am trying to get a handle on an external process (Internet
Explorer
6 in
> > this case) that I open using win32process. I need the handle so that
I
can
> > make said process the top window. 

> When you call CreateProcess, that window should automatically become
the

> top window.  Are you saying that's not happening?  Have you tried 
> creating a STARTUPINFO struct and filling in the wShowWindow element?

Sorry, I guess I thought more than I actually typed. It does make the
newly created window the top window. But later on in my program, I open
the source code for the displayed page and will need to make sure that I
return to the correct IE instance, which is why I wanted a handle on the
IE window. I thought I knew the correct terminology to express this, but
I
guess not.

<snip>

> >
> > # attempt to make Internet Explorer 6 the Foreground Window
> > win32gui.SetForegroundWindow(handle)
> >   

> No, the error message is right.  A process handle is not the same as a

> window handle.  Indeed, a process need not have any windows at all.

> > I can get the handle by doing this:
> >
> > hwnd = win32gui.FindWindow('IEFrame',None)
> >
> > But if there's multiple Explorer windows open, I may not get the
window I
> > want. That's why I would like to create my own so I can have what
amounts
> > to an "exclusive" handle to it. Any hints would be appreciated.
> >   

> One possibility is to enumerate through all of the top-level windows 
> using EnumWindows, and for each window call GetWindowThreadProcessId
to 
> find the process ID associated with that window to find the one that 
> matches your process.  Remember that the process ID is not the same as
a

> process handle; the process ID is the third thing in the tuple 
> CreateProcess returns.

Yeah, I am well aware of this method and was hoping to avoid it. Thanks
for the clarification on window handle versus process handle. I was
thinking about this the wrong way because I thought they were the same.


> -- 
> Tim Roberts, timr at probo.com
> Providenza & Boekelheide, Inc.

Mike Driscoll
Applications Specialist
MCIS - Technology Center




------------------------------

Message: 3
Date: Wed, 23 Jan 2008 09:27:34 -0600 (CST)
From: "Mike Driscoll" <mdriscoll at co.marshall.ia.us>
Subject: Re: [python-win32] Creating a process and getting a handle
To: <python-win32 at python.org>
Message-ID: <003501c85dd4$6cc52b10$96c051d8 at mcis0492>
Content-Type: text/plain;	charset="us-ascii"

Alec,

> 
> Date: Tue, 22 Jan 2008 23:26:50 -0800 (PST)
> From: Alec Bennett <whatyoulookin at yahoo.com>
> Subject: Re: [python-win32] Creating a process and getting a handle
> To: Tim Roberts <timr at probo.com>, Python-Win32 List
> 	<python-win32 at python.org>
> Message-ID: <316017.40385.qm at web54603.mail.re2.yahoo.com>
> Content-Type: text/plain; charset=iso-8859-1
> 
> Please post what you find on this, I'm curious too.
> 
> If you do go the enum windows route, It thought I'd
> post my notes on this since I recently got it working.
> It's somewhat confusing (for me at least) since it
> uses a callback:
> 
> 
> # Callback function for findWindowHandle
> def windowEnumerationHandler(hwnd, resultList):
> 
>     resultList.append((hwnd,
> win32gui.GetWindowText(hwnd)))
> 
> 
> def findWindowHandle(string):
> 
>     topWindows = []
> 
>     win32gui.EnumWindows(windowEnumerationHandler,
> topWindows)
> 
>     for window in topWindows:
>         if string in window[1]: return window[0],
> window[1]
> 
>     # Looks like we didn't find anything
>     return None, None
> 
> 
> handle, windowtext = findWindowHandle("Notepad")

I actually use a method similar to this later on in my program. But as I
mentioned to Tim, I was trying to get a handle on a window that I open
so
I wouldn't have to search for it. I use the search method already to
find
the source code window that I open from within IE. Sometimes automation
sucks.

Mike Driscoll
Applications Specialist
MCIS - Technology Center



------------------------------

Message: 4
Date: Wed, 23 Jan 2008 09:33:27 -0600 (CST)
From: "Mike Driscoll" <mdriscoll at co.marshall.ia.us>
Subject: Re: [python-win32] Creating a process and getting a handle
To: "'Tim Golden'" <mail at timgolden.me.uk>
Cc: python-win32 at python.org
Message-ID: <003801c85dd5$3efd1610$96c051d8 at mcis0492>
Content-Type: text/plain;	charset="us-ascii"

Hi Tim G., 

<snipped for brevity>

> > I can get the handle by doing this:
> > 
> > hwnd = win32gui.FindWindow('IEFrame',None)
> > 
> > But if there's multiple Explorer windows open, I may not get the 
> > window I want. That's why I would like to create my own so 
> I can have 
> > what amounts to an "exclusive" handle to it. Any hints 
> would be appreciated.
> 
> I thought I'd posted a How-Do-I? on this one, but obviously 
> not. At any rate, here's the code I intended to post up. Hope 
> it helps as a starting point:
> 
> <code>
> import subprocess
> import time
> 
> import win32con
> import win32gui
> import win32process
> 
> 
> def get_hwnds_for_pid (pid):
> 
>    def callback (hwnd, hwnds):
>      if win32gui.IsWindowVisible (hwnd) and 
> win32gui.IsWindowEnabled (hwnd):
>        _, found_pid = win32process.GetWindowThreadProcessId (hwnd)
>        if found_pid == pid:
>          hwnds.append (hwnd)
>      return True
> 
>    hwnds = []
>    win32gui.EnumWindows (callback, hwnds)
>    return hwnds
> 
> if __name__ == '__main__':
>    notepad = subprocess.Popen ([r"notepad.exe"])
>    #
>    # sleep to give the window time to appear
>    #
>    time.sleep (2.0)
> 
>    for hwnd in get_hwnds_for_pid (notepad.pid):
>      print hwnd, "=>", win32gui.GetWindowText (hwnd)
>      win32gui.SendMessage (hwnd, win32con.WM_CLOSE, 0, 0)
> 
> </code>
> 
> TJG
> 

I think this will work. It's a little bit quicker than the method Alec
mentioned (and which I use in another part of my app) and it's
definitely
a little less confusing. I just tested it by opening a couple other
instances of Notepad before running it and your script kills only the
Notepad process that it opens, as expected. Very cool.

Thanks for helping me once again.

Mike



------------------------------

Message: 5
Date: Wed, 23 Jan 2008 10:11:14 -0800
From: Tim Roberts <timr at probo.com>
Subject: Re: [python-win32] Getting Network Information/Statistics
To: Python-Win32 List <python-win32 at python.org>
Message-ID: <47978342.4000303 at probo.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

 >.> wrote:
> I got the interface name from win32util.browse() in Vista and XP. I 
> think XP is Giving me the wrong number because it differs from what 
> I'm reading in perfmon everytime and it seems to be counting down from

> that number after every subsequent call.
> ex: perfmon will give me a last of 0.0 and
>  win32pdhutil.GetPerformanceAttributes('Network Interface','Bytes 
> Received/sec','Intel[R] PRO_100 VE Network Connection - Packet 
> Scheduler Miniport')
>
> Will return something like 12107 and will go down every subsequent
call.

Insert a call to win32pdh.CollectQueryData(hq) before you fetch the 
counter value.  The counters are only fetched when you send a query, and

that's done with CollectQueryData.

For me, this produces exactly the same numbers as perfmon:

import win32pdh
import time
intf = "NVIDIA nForce Networking Controller - Packet Scheduler Miniport"
hq = win32pdh.OpenQuery()
cp = win32pdh.MakeCounterPath( (None, 'Network Interface', intf, None, 
-1, 'Bytes Received/sec') )
hc = win32pdh.AddCounter( hq, cp )
for i in range(100):
    win32pdh.CollectQueryData( hq )
    tp,val = win32pdh.GetFormattedCounterValue( hc,
win32pdh.PDH_FMT_LONG )
    print hex(tp),val
    time.sleep(1)

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



------------------------------

Message: 6
Date: Wed, 23 Jan 2008 10:16:16 -0800
From: Tim Roberts <timr at probo.com>
Subject: Re: [python-win32] Export emails from msoutlook to my local
	directory
To: Python-Win32 List <python-win32 at python.org>
Message-ID: <47978470.6050802 at probo.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Antony Joseph wrote:
>
> 1.Export emails from msoutlook to my local directory
>
> The problem i am facing is that the embedded images are
> getting as attachments

Of course, because that's exactly how they are sent.  What did you 
expect?  Email is a textual media.  There's no such thing as an embedded

image.  Images are always sent as named attachments, and HTML tags in 
the message can tell the mail reader to display a particular image at a 
particular point, but even that varies from mail program to mail
program.
 

> Any body help me to solve this problem.

What problem?

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



------------------------------

Message: 7
Date: Wed, 23 Jan 2008 10:21:35 -0800
From: Tim Roberts <timr at probo.com>
Subject: Re: [python-win32] python layoutdialog
To: Python-Win32 List <python-win32 at python.org>
Message-ID: <479785AF.90801 at probo.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

kNish wrote:
>         Maya python command layoutDialog, in my view works strange. It
> takes the procedure from MEL equivalent if exists else gives an error.
> How may I successfully execute a layoutDialog in python in maya.
>   

This is a Maya question, so you should ask on a Maya mailing list.  My 
friend Google points to an example usage of layoutDialog here:
    
http://www.kxcad.net/autodesk/maya/Maya_Documentation/CommandsPython/lay
outDialog.html

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



------------------------------

Message: 8
Date: Wed, 23 Jan 2008 19:04:22 -0500
From: ">.>" <twopill at gmail.com>
Subject: Re: [python-win32] Getting Network Information/Statistics
To: python-win32 at python.org
Message-ID:
	<cb5389360801231604l3ab18187s4c2394604e75c458 at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

That works for XP but not Vista, I guess M$ changed the API in Vista. Oh
by
the way I mean to write win32pdhutil.browse() earlier. Thanks for the
help.
I didn't run it as admin in Vista before so I gave your script a try.
The output from your script as run in vista by administrator follows:
[code]
>>> win32pdhutil.browse()
Value of '\Network Interface(Intel[R] PRO_100 VE Network
Connection)\Current
Bandwidth' is 100000000.0
Added 'Current Bandwidth' on object 'Network Interface' (machine
\\SAIBOX-01), instance Intel[R] PRO_100 VE Network Connection(0)-parent
of
None
>>>
Traceback (most recent call last):
  File
"C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py"
,
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python25\getrcv.py", line 10, in <module>
    tp,val = win32pdh.GetFormattedCounterValue( hc,
win32pdh.PDH_FMT_LONG )
error: (-1073738810, 'GetFormattedCounterValue', 'No error message is
available')
>>>
[/code]
I'm new to working in windows and am curious as to how to go about
getting
the error codes, I tried hex(1073738810) but thats not right.


On Jan 23, 2008 1:11 PM, Tim Roberts <timr at probo.com> wrote:

>  >.> wrote:
> > I got the interface name from win32util.browse() in Vista and XP. I
> > think XP is Giving me the wrong number because it differs from what
> > I'm reading in perfmon everytime and it seems to be counting down
from
> > that number after every subsequent call.
> > ex: perfmon will give me a last of 0.0 and
> >  win32pdhutil.GetPerformanceAttributes('Network Interface','Bytes
> > Received/sec','Intel[R] PRO_100 VE Network Connection - Packet
> > Scheduler Miniport')
> >
> > Will return something like 12107 and will go down every subsequent
call.
>
> Insert a call to win32pdh.CollectQueryData(hq) before you fetch the
> counter value.  The counters are only fetched when you send a query,
and
> that's done with CollectQueryData.
>
> For me, this produces exactly the same numbers as perfmon:
>
> import win32pdh
> import time
> intf = "NVIDIA nForce Networking Controller - Packet Scheduler
Miniport"
> hq = win32pdh.OpenQuery()
> cp = win32pdh.MakeCounterPath( (None, 'Network Interface', intf, None,
> -1, 'Bytes Received/sec') )
> hc = win32pdh.AddCounter( hq, cp )
> for i in range(100):
>     win32pdh.CollectQueryData ( hq )
>    tp,val = win32pdh.GetFormattedCounterValue( hc,
win32pdh.PDH_FMT_LONG )
>    print hex(tp),val
>    time.sleep(1)
>
> --
> Tim Roberts, timr at probo.com
> Providenza & Boekelheide, Inc.
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://mail.python.org/pipermail/python-win32/attachments/20080123/a13a8
525/attachment.htm 

------------------------------

_______________________________________________
python-win32 mailing list
python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32


End of python-win32 Digest, Vol 58, Issue 38
********************************************


More information about the python-win32 mailing list