简体   繁体   English

计算机状态(睡眠,休眠,锁定等)Windows 10

[英]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.

相关问题 在计算机锁定时,为关闭计算机而创建的Windows服务无效 - Windows service created to shut down computer is not working when computer is locked Windows 10睡眠问题。 图形消失了 - Windows 10 Sleep Issue. Graphics disappearing Windows-在运行测试之前检查计算机是否已锁定/注销 - Windows - Check if computer is locked/logged out before running tests Active Directory在Windows服务中获取锁定/解锁状态 - Active Directory Acquiring Locked/Unlocked status in a Windows Service 在锁定的 Windows 10 机器上的后台进程中将文本放入剪贴板 - Put text to clipboard in the background process on locked Windows 10 machine 从.NET Windows服务检测系统待机/睡眠/休眠? - Detect system standby/sleep/hibernate from .NET Windows Service? 如何抓住上次从睡眠或休眠模式中醒来的窗口? - How to grab last time windows awoke from sleep or hibernate modes? 当计算机在 .net 4.5 中从睡眠/休眠模式恢复时,如何捕获事件? - How can I catch an event when the computer resume from sleep/hibernate mode in .net 4.5? 状态栏的颜色-Windows 10移动版 - Color of status bar - Windows 10 Mobile 获取 Windows 10 中夜灯模式的状态 - Get status of night light mode in Windows 10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM