Menu

#94 add AddEnglishCounter in win32pdh

closed-fixed
nobody
win32 (43)
5
2012-06-04
2012-05-24
Sebastian
No

Counter paths in win32pdh are language dependent. For instance, the following code will raise a pywintypes.error when run on a not English Windows.:

import win32pdh
path = win32pdh.MakeCounterPath(( None, 'System', None, None, 0, 'System Up Time'))
query = win32pdh.OpenQuery()
handle = win32pdh.AddCounter(query, path)

E.g., to make that work on a Spanish Windows, the MakeCounterPath line should be:
path = win32pdh.MakeCounterPath(( None, 'Sistema', None, None, 0, 'Tiempo de actividad del sistema'))

Which makes it real hard to distribute a solution that is supposed to run on different language platforms.

To avoid that, there's this PdhAddEnglishCounter function: http://msdn.microsoft.com/en-us/library/windows/desktop/aa372536\(v=vs.85).aspx
Which is not implemented on pywin. If implemented, this should work on any windows language:

import win32pdh
path = win32pdh.MakeCounterPath(( None, 'System', None, None, 0, 'System Up Time'))
query = win32pdh.OpenQuery()
handle = win32pdh.AddEnglishCounter(query, path)

AddCounter and AddEnglishCounter functions have the same signature. I guess that adding the following to win32pdhmodule.cpp should be enough:

typedef PDH_STATUS (WINAPI * FuncPdhAddEnglishCounter)(
HQUERY hQuery, // handle to the query
LPCTSTR szFullCounterPath, // path of the counter
DWORD_PTR dwUserData, // user-defined value
HCOUNTER *phCounter // pointer to the counter handle buffer
);

Discussion

  • Roger Upole

    Roger Upole - 2012-06-04

    AddEnglishCounter has been added to win32pdh.

     
  • Roger Upole

    Roger Upole - 2012-06-04
    • status: open --> closed-fixed
     

Log in to post a comment.