[英]Computer Status (Sleep, Hibernate, Locked, etc) Windows 10
I need to check the current state of the Computer. 我需要检查计算机的当前状态 。 Hibernate, Sleep, onStand-by Locked, etc
Hibernate,Sleep,onStand-by Locked等
I Just want to Ask on how to get the current status of my computer using C#? 我只想询问如何使用C#获取计算机的当前状态? I have already get when the computer is locked by detecting the LockApp process but I can't get if it is on sleep mode, or hibernate.
我已经通过检测LockApp进程锁定计算机,但是如果它处于睡眠模式或休眠状态,我就无法获得。
I want to try a project that will run using the task scheduler and check the current state of the computer and will show on the console. 我想尝试一个将使用任务调度程序运行的项目,并检查计算机的当前状态,并将显示在控制台上。
Please note that I is to detect the state of the computer when my project runs. 请注意,我将在项目运行时检测计算机的状态。 Thank you.
谢谢。 And sorry for my bad English.
抱歉我的英语不好。 :)
:)
//Will return true if the Computer is Locked
public bool Lock()
{
Boolean locked = false;
Process[] LockApp = Process.GetProcesses();
foreach (Process theprocess in LockApp)
{
if (theprocess.ProcessName == "LockApp")
{
locked = true;
Console.WriteLine("LockApp: " + locked.ToString());
}
}
return locked;
}
//Will return true if still on Startuptime (+5min)
public bool onStartupTime()
{
bool oST = false;
DateTime ST = DateTime.Now.AddMilliseconds(-
Environment.TickCount);
DateTime Less = DateTime.Now.AddMinutes(-5);
DateTime Now = DateTime.Now;
Console.WriteLine(ST.ToString("yyyy-MM-dd HH:mm:ss"));
Console.WriteLine(Less.ToString("yyyy-MM-dd HH:mm:ss"));
Console.WriteLine(Now.ToString("yyyy-MM-dd HH:mm:ss"));
if (ST >= Less)
{
oST = true;
}
return oST;
}
OnStartup(-5mins): true or false Lock: true or false Sleep: true or false hibernate: true or false OnStartup(-5分钟):true或false锁定:true或false睡眠:true或false hibernate:true或false
According to this link , you can do it using SystemEvents.PowerModeChanged
. 根据此链接 ,您可以使用
SystemEvents.PowerModeChanged
执行此操作。 An example of using is also posted there: 使用的一个例子也发布在那里:
SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(OnPowerModeChanged);
private static void OnPowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
switch (e.Mode)
{
case PowerModes.Resume:
MessageBox.Show("PowerMode: OS is resuming from suspended state");
break;
case PowerModes.Suspend:
MessageBox.Show("PowerMode: OS is about to be suspended");
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.