In the past, I did not know how to shut down at a time, so I used QT to write a program for implementation.
There are two key points: 1. Get the time difference from the scheduled start to the present
2. How to disable a computer
You can use Windows API to disable a computer. Here, we need to install windows. h of mingw \ include in the QT creator directory. If the VC compiler is used, use Windows. h in VC.
The Code is as follows. You can call this function to disable the computer function.
1 # include "windows. h" 2 3 bool shutdown: mysystemshutdown () 4 {5 handle htoken; 6 token_privileges tkp; 7 8 // get process flag 9 If (! Openprocesstoken (getcurrentprocess (), token_adjust_privileges | token_query, & htoken) 10 return false; 11 12 // luid13 lookupprivilegevalue (null, se_shutdown_name, & tkp. privileges [0]. luid); 14 tkp. privilegecount = 1; 15 tkp. privileges [0]. attributes = se_privilege_enabled; 16 17 // get the shutdown privilege of this process 18 adjusttokenprivileges (htoken, false, & tkp, 0, (ptoken_privileges) null, 0 ); 19 if (getlasterror ()! = Error_success) return false; 20 21 // force disable computer 22 if (! Exitwindowsex (ewx_shutdown | ewx_force, 0) 23 return false; 24 return true; 25}