Recently, I have been trying to find a method of completely automating my backup system, which uses a 3rd-party program called "AOMEI Backupper Standard". The automated sequence I am trying to get the computer to perform consists of:
- Powering on the PC slightly before noon each day and initialising a set of two incremental backups at noon, which will run sequentially until completion. The total time that these two backups take to execute is currently around 2 hours 55 mins (I have a lot of data to read, even with a striped volume), though this time will likely increase as I accumulate more data in the future.
- At completion, the PC needs to verify whether someone has been using the computer for any significant period of time (say 5 mins or more to ignore quick usages or random disturbances), during a time period (say 1 hour) before the 2nd backup completed. Alternatively, instead of verifying if there has been use for more than 5 mins, the PC could simply detect any use longer than 1 minute (to eliminate random errors with the keyboard or mouse being nudged or moving slightly) and then there could be another script for resetting the usage flag if the user wants the PC to ignore their previous usage during the 1 hour time period.
- If there has not been significant user activity in that time period, then the PC must automatically hibernate at the end of the 2nd backup (this completes the automated process for if I am not at home/using the PC). Otherwise, the PC must abort the hibernation if it detects this user activity, so that it doesn't suddenly power off whilst I am using it, or if I have been using it recently.
I can handle the setting of the start of the timing period using a batch file by taking the previous time that the two backups took to complete, adding that on to midday, and then subtracting 1 hour. This will allow the start of the timing period to become later relative to noon as the total backup time increases with more data being stored.
Therefore, I am looking for a way to detect user activity on the PC during the time period by either checking mouse and/or keyboard input, or by some other means. This detection method would also need to take into account if the "ES_DISPLAY_REQUIRED" flag had been set, or similar, so that the PC would not be considered idle if it was being used to watch a movie where there is no user input for a long time.
One idea I had for detection other than directly checking M&K, was to somehow utilise the Windows idle flag/state, but modify it to ignore resource consumption as a factor in determining idle state. This is because during the backup, the CPU and IO percentage idle time will easily be less than the 80% threshold set by Microsoft (see this page from Microsoft for more details) for Windows 8 (although I assume this also applies for Windows 10 systems, which is what I am currently using as my OS), and so the system would never become "idle" even if there were no mouse or keyboard input/user presence during this period.
Ideally, I would like to be able to do this detection using a batch file/Windows command line (cmd), but I can appreciate that this may not be possible for this type of task. Therefore, if you have any suggestions for other programming languages which would integrate/work well with Windows and would be able to accomplish this task, I would be happy to hear them (I have some basic experience with HTML/CSS and JavaScript, as well as a moderate level of experience with Visual BASIC and Command Line/Batch Files). Sorry if this was a little too verbose, but I wanted to prevent any confusion about my problem.
Thanks in advance for your time.
EDIT #1: I have generalised the title to move away from my original choice of using batch files only, and I have added a tag for C# as I understand that it is similar to VB and can be useful for tasks in Windows.
EDIT #2: After doing some more research, I have come to the realisation that PowerShell may be another much more powerful option than batch files, as it has much more advanced capabilities than cmd. For now, I will try to do some research into learning PowerShell and looking over related questions such as this one, as it seems like what I'm trying to achieve could be done without a lot of complicated code using this language.
EDIT #3: It seems that my generalisation over multiple languages due to me not knowing which would solve my problem wasn't appreciated, and so I am now re-focusing the question onto only PowerShell. This is because the problem is apparently "not C# related" and I am almost certain now that it cannot be accomplished using cmd, as there simply isn't a command for detecting mouse or keyboard input.