views:

55

answers:

2

I know Environment.TickCount exist but I have a big problem with that, it's limited to 25 days.

what would be a good alternative that require no external module/dll and would work in a vanilla install of windows server 2003?

thanks

+1  A: 

Plenty of choices.

public TimeSpan SystemUpTime()
{
    PerformanceCounter upTime = 
        new PerformanceCounter("System", "System Up Time");

    // You've got to call this twice. First time it returns 0 
    // and the second time it returns the real info.
    upTime.NextValue();   
    return TimeSpan.FromSeconds(upTime.NextValue());
}

This, however, won't run if you don't have sufficient privileges.

You can also use WMI

Anton Gogolev
A: 

You can use WMI to get WIN32_OperatingSystem.LastBootUpTime.

Quassnoi