0

I have written a batch script to perform some folder synchronizing task. I have scheduled the script to execute using task scheduler on events such as sleep/hibernate(kernel power event id 42) and shutdown (user32 event id 1074). The script is initiating on these events but it get stopped in between and computer goes to sleep/hibernate/shutdown and afterwards when I turned on the computer the script resumes. I want the script to complete first and then the computer should go off.

can someone provide me the solution to this or any alternate way to achieve the task.

This is the screenshot of my script test.bat

This the modified script but it doesn't worked.

@echo OFF
set LogFile="C:\Users\Harsh Lulla\Desktop\TestLog.txt"
REM changing to High performance mode
powercfg /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
powercfg /list >> %LogFile% 2>&1
echo %date% %time% Script Started. Running rclone sync command...>> %LogFile% 
echo %date% %time% Syncing local system device with NAS... >> %LogFile% 
rclone sync -n -v E:\test sftpNAS:/test/test >> %LogFile% 2>&1
echo %date% %time% rclone command completed. Script completed >> %LogFile%
REM changing to normal mode
powercfg /setactive 49ef8fc0-bb7f-488e-b6a0-f1fc77ec649b 
6
  • Please post the essentials of your script. Commented Feb 1 at 6:39
  • I have added screenshot of the script
    – Harsh
    Commented Feb 1 at 11:14
  • @Harsh Please do not screenshot text - instead, please copy/paste the script text within a code box in the question. It would also be helpful to see the task - please export the task in Task Scheduler, open the export in a text editor, then copy/paste it into a code box. A simple fix would be modifying the power settings at the start of the script (e.g. changing to Performance), then setting it back to normal at the end of the script.
    – JW0914
    Commented Feb 1 at 13:04
  • I have modified the script as you said but that doesn't worked as required.
    – Harsh
    Commented Feb 2 at 4:42
  • You do understand that that script, even if it were ran when the system was shutting down, would not prevent the shutdown of the system. So the script would end prematurely. Is that your problem or is it you can't figure out how to run it when the system is shutting down?
    – Ramhound
    Commented Feb 2 at 4:52

0

You must log in to answer this question.