Remote uptime with win32pdh

J

Jamie

I'm new to python and I'm trying to write a script which takes the
computer name from the variable 'name' and gets the uptime.

What I have so far:
query = win32pdh.OpenQuery()
counter = win32pdh.AddCounter(query, r'\System\System Up Time')
win32pdh.CollectQueryData(query)
var1, val = win32pdh.GetFormattedCounterValue(counter,
win32pdh.PDH_FMT_LONG)
uptime = val / 3600

print "--> Uptime: %s hours" % uptime

That works just fine for the local system, but I'm at a loss figuring
out how to make it gater that data from a remote system. Any help
would be much appreciated!
 
J

Jamie

I'm new to python and I'm trying to write a script which takes the
computer name from the variable 'name' and gets the uptime.

What I have so far:
    query = win32pdh.OpenQuery()
    counter = win32pdh.AddCounter(query, r'\System\System Up Time')
    win32pdh.CollectQueryData(query)
    var1, val = win32pdh.GetFormattedCounterValue(counter,
win32pdh.PDH_FMT_LONG)
    uptime = val / 3600

    print "--> Uptime: %s hours" % uptime

That works just fine for the local system, but I'm at a loss figuring
out how to make it gater that data from a remote system. Any help
would be much appreciated!

Oh, and I can't use WMI because WMI doesn't seem to work in Portable
Python (long story)
 
J

Jamie

Oh, and I can't use WMI because WMI doesn't seem to work in Portable
Python (long story)- Hide quoted text -

- Show quoted text -

path = win32pdh.MakeCounterPath((name, r'System', None, None, 0,
"System Up Time"))
query = win32pdh.OpenQuery()
handle = win32pdh.AddCounter(query, path)
win32pdh.CollectQueryData(query)
seconds = win32pdh.GetFormattedCounterValue(handle,
win32pdh.PDH_FMT_LONG | win32pdh.PDH_FMT_NOSCALE )[ 1 ]

uptime = seconds / 3600


that works! ;)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top