With TWAPI, I can get the time that different users logged on. I´ve
also found a registry key that stores the time of the last system
shutdown. But still I can´t find any way to get the system uptime.
I can parse the time from the output of the following system commands,
but running these commands with [exec] gives no return value, so I
can´t access the output within Tcl:
net statistics workstation
net statistics server
Now I´m trying to do it by reading the Windows event log through
TWAPI, but still no luck.
Any ideas? Thanks in advance.
Paul
exec net statistics server
With tclsh, the exec command returns the output, but in wish it just
returns an empty string,
It seems that the 'NET' command is only working from a console window
correctly. I tried several ways to capture the output (e.g. redirecting to a
file) but none of them worked. Also one can see a DOS box flicker when
calling the command from wish. For me the NET command is programmed in a way
like: "If I'm not started from the console, let's open it by myself"
That way it sure prevents capturing the output. I also tried opening a pipe
or calling it indirectly with 'exec cmd.exe /c ...'. None of them worked.
Seems we have to thank Big Bill once more ;-)
Regards - Leo
Ilya
"Leopold Gerlinger" <leopold....@siemens.com> wrote in message
news:dmh37r$el5$1...@mail1.sbs.de...
set token [open uptime.bat w]
puts $token "net statistics server"
close $token
set data [exec uptime.bat]
file delete uptime.bat
And then it´s just a matter of parsing the output to get the last boot
time. But if anyone else uses this method, be advised that the output
is in the user´s preferred language, so some fancy parsing is required
to be international.
Also, I don´t think this command is available on Windows 98.
Hmm.. uptime.. Your answer is:
% winutils::duration [winutils::uptime]
proc ::winutils::duration { int_time } {
set timeList [list]
foreach div {86400 3600 60 1} mod {0 24 60 60} name {day hr min sec} {
set n [expr {$int_time / $div}]
if {$mod > 0} {set n [expr {$n % $mod}]}
if {$n > 1} {
lappend timeList "$n ${name}s"
} elseif {$n == 1} {
lappend timeList "$n $name"
}
}
return [join $timeList]
}
The performance counter used is "\\System\\System Up Time", FYI. If
TWAPI can query performance counter bits, you won't need my C source.
package require twapi
twapi::get_counter_path_value {\\.\System\System Up Time} -interval 0
Twapi has a full interface to the Windows performance counters but it
is undocumented as I'm not entirely happy with its complexity and am
planning to modify it at some point.
/Ashok