如何获取带有日期和时间的上次系统关闭状态 [英] How To get Last System Shut Down Status With Date and Time

查看:81
本文介绍了如何获取带有日期和时间的上次系统关闭状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要c#中的以下内容:-

1.上次系统关闭来自事件查看器的日期和时间.事件ID = 1078
2.上次系统关闭模式,即正确关闭/意外关闭(错误关闭)事件ID = 6006
3.总系统运行时间.总正常运行时间.
以上所有内容在事件查看器中都可用,但是如何使用WMI C#获得唯一的最后一条记录.


问候

I need the Following things in c#:-

1. Last system OFF Date and Time From event Viewer. Event ID = 1078
2. Last System OFF mode i.e Proper shut down / un expected (improper Shut Down) Event ID = 6006
3. Total System Running duration. Total Up Time.
All the above things are available in Event Viewer, but how can I get the only last record using WMI C#.


Regards

推荐答案


试试这个代码:
Hi,
try this code:
private void button1_Click(object sender, EventArgs e)
{
   MessageBox.Show(GetLastSystemShutdown().ToString());
}

public static DateTime GetLastSystemShutdown()
{
   string sKey = @"System\CurrentControlSet\Control\Windows";
   Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sKey);

   string sValueName = "ShutdownTime";
   byte[] val = (byte[])key.GetValue(sValueName);
   long valueAsLong = BitConverter.ToInt64(val, 0);
   return DateTime.FromFileTime(valueAsLong);
}


这篇关于如何获取带有日期和时间的上次系统关闭状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆