我原先是用GetTickCount来算出系统的启动时间,但系统要是启动超过49.7天后,就会出现重新变成0
因为这个GetTickCount函数返回的是INT32类型,到了最大值 就头开始了因此我就想到另外一个解决方案就是调用NtQuerySystemInformation,来查出启动时间
但是网上找了好久都没找到现成的C#调用此函数的完整代码,因此来这边问问喽,呵呵~~或者用其它方法如WMI用否查出启动时间呢?

解决方案 »

  1.   

    GetTickCount 确实有问题,看看他的原理,重构一个算了
      

  2.   

    你可以用GetSystemTimes这个api,例如:
    [DllImport("kernel32.dll", SetLastError=true)]
    static extern bool GetSystemTimes (
    out FILETIME lpIdleTime,
    out FILETIME lpKernelTime,
    out FILETIME lpUserTime
    );
    struct FILETIME 
    {
    public uint DateTimeLow;
    public uint DateTimeHigh;}//call 
    FILETIME lpIdleTime, lpKernelTime, lpUserTime;
    GetSystemTimes( out lpIdleTime, out lpKernelTime, out lpUserTime );
    ulong lngKernelTime = ((ulong)lpKernelTime.DateTimeHigh << 32)
    + lpKernelTime.DateTimeLow;
    ulong lngUserTime = ((ulong)lpUserTime.DateTimeHigh << 32)
    + lpUserTime.DateTimeLow;
    double dRunTime = lngKernelTime + lngUserTime;
    dRunTime /= ( TimeSpan.TicksPerMillisecond * 60 * 60 * 1000 );
    Debug.WriteLine( dRunTime.ToString( "f2"  ) );
      

  3.   

    有空帮我看看这个
    http://community.csdn.net/Expert/topic/5147/5147770.xml?temp=.1404077