如何在关闭PC之前设置系统的唤醒时间? [英] How do I set the wake up time to system before shutdown the PC?

查看:364
本文介绍了如何在关闭PC之前设置系统的唤醒时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#新的,我正在开发的项目在C#.net Windows应用程序,我需要从我的计划文件中读取下一个计划时间,如果没有计划下一个小时,我的系统不需要唤醒直到在日程文件中定义的下一个日程时间到达。我的系统需要关机,在关机之前,需要设置系统唤醒的定时器。如何在关机之前将系统设置为关闭我的pc。
我在Linux系统中通过python脚本通过在 / sys / class / rtc / rtc0 / wakealaram 位置。我只是写下一个系统的时间在这个位置,并关闭系统,系统可以自动开启达到在 wakealaram 文件中给出的时间。我需要在Windows系统中使用C#做同样的。

解决方案

请看下面。

  #region时钟重置
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public short Year;
public short月;
public short DayOfWeek;
public short Day;
public short小时;
public short分钟;
public short Second;
public short毫秒;
}
[DllImport(kernel32.dll)]
public extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);

private void ResetSystemTime(DateTime tdt)
{
try
{

SYSTEMTIME time = new SYSTEMTIME
time.Day =(short)tdt.Day;
time.Month =(short)tdt.Month;
time.Year =(short)tdt.Year;
time.Hour =(short)tdt.Hour;
time.Minute =(short)tdt.Minute;
time.Second =(short)tdt.Second;
SetSystemTime(ref time);
}
catch(Exception ex)
{
MessageBox.Show(System time reset Exception:+ ex.Message);
}
}
#endregion


I am new in C#, I am developing the project at C#.net windows application in that I need to read the next schedule time from my schedule file, if there is no schedule for next one hour, my system need not to wake on until next schedule time reach which is defined in schedule file. My system needs to shutdown, and before shutdown it need to set the timer for system wake. How to set the system on time before shutdown my pc.
I did this same in Linux system through python script by writing the system on time at /sys/class/rtc/rtc0/wakealaramlocation. I just write the next system on time at this location and shutdown the system, the system can be automatically on by reach the time which is given in wakealaram file. I need to do the same in Windows system by using C#.

解决方案

Have a look at below.

#region Clock Reset
    [StructLayout(LayoutKind.Sequential)]
    public struct SYSTEMTIME
    {
        public short Year;
        public short Month;
        public short DayOfWeek;
        public short Day;
        public short Hour;
        public short Minute;
        public short Second;
        public short Milliseconds;
    }
    [DllImport("kernel32.dll")]
    public extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);

    private void ResetSystemTime(DateTime tdt)
    {
        try
        {

            SYSTEMTIME time = new SYSTEMTIME();
            time.Day = (short)tdt.Day;
            time.Month = (short)tdt.Month;
            time.Year = (short)tdt.Year;
            time.Hour = (short)tdt.Hour;
            time.Minute = (short)tdt.Minute;
            time.Second = (short)tdt.Second;
            SetSystemTime(ref time);
        }
        catch (Exception ex)
        {
            MessageBox.Show("System time reset Exception: " + ex.Message);
        }
    }
#endregion

这篇关于如何在关闭PC之前设置系统的唤醒时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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