如何在关闭PC之前设置系统的唤醒时间? [英] How do I set the wake up time to system before shutdown the 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/wakealaram
location. 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屋!