Issue: Reflect v7.3 with "Macrium Task Scheduler" and OS-Hibernation...


Author
Message
Joachim
Joachim
Junior Member
Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)
Group: Forum Members
Posts: 42, Visits: 66
Windows 10 Pro, x64, Version 2004, Build 19041.572; Hibernation 'On' - after 20 minutes.
Macrium Reflect, Version 7.3.5289, "Use the Macrium Task Scheduler"; Task-Environment: SYSTEM; Scheduler condition only: “Wake the computer to run this task”.

Hello,
I am using Reflect since v 7.1.xxxx. And I have automated my Backups with VBScript. After updating Reflect from v7.2.5107 to v7.3.5289 AND selecting recommended "Macrium Task Scheduler", my previous working Backup-Script will stopped during execution, because the OS enters the Hibernation-Mode.
Waking-up the PC (e.g. via Keyboard stroke) the script proceed running... until next hibernation.
This problem occurs under VBScript and PowerShell repeatable!

Workaround: Select "Use Windows Task Scheduler" and the same script works fine again - without hibernation / breaks.
Solving the problem fundamental: Make sure that a script, initiated and executed by Macrium Task Scheduler, is not interrupted by power saving modes such as hibernation, while it is running.

Details to the scripts:
My VBScript (the tested PowerShell-Script, too) was generated based to a Backup-definition as described.
Inside the Scripts-Main-Sections directly before "ExitCode = Backup (...)" an additional program runs like:
objShell.Run """C:\Program Files (x86)\<Path>\<Program.exe>"" /Read:""%ProgramFiles(x86)%\<Path>\<File.txt>"" /EventTextSelect:01 /NASon", 1, True
ExitCode = Backup (...)

This additional program looks if the NAS (Backup-target) is on, starts it if necessary, waits until NAS is ping able, waits some additional seconds until NAS can receive the Backup and writes an own detailed log file. This program (with 'wait'-Option) needs round about 5 minutes.
After / during executing this part of the whole backup script, the PC enters Hibernation and the script stops. (The script is continued after the wake-up.)

After executing the "ExitCode = Backup (...)" lines my additional Program starts again (with other parameters) and - in dependence on the results from first run - my NAS will be shutdown or...
This Program-call will take about 3 - 5 Minutes and after this, the next Hibernation occurs, before the PC-shutdown command is running.

To verify, if this is a (new) problem in VBScript, I created a PowerShell-Script with the same functionality and start my additional Program like:
Start-Process -FilePath $strRunAtStartApp -ArgumentList $strRunAtStartArgs -wait;
$iExitCode = Backup;

Under "Macrium Task Scheduler" it shows the same hibernation behaviours.
Selecting the "Use Windows Task Scheduler" this script also works fine, too.

IMPORTANT: To verify the hibernation issue with "Macrium Task Scheduler" it's sufficient to add a 'WScript.Sleep' instead of my 'additional Program' (see above) into the VBScript, like:
WScript.Sleep 360000 ' 6 minutes delay
' Do the backup
ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\ReflectBin.exe"" -e -w <BACKUP_TYPE> ""E:\Benutzer\<User>\Documents\Reflect\Test_2.xml"" -g")

Then start the script via "Scheduled Backups". The Hibernation modes occur within oder after the '6 minutes delay'! (Possible, the script starts itself after the ‘6 minutes delay’.)


Supplement (not fully or individually tested due to lack of time - possible in conjunction with the issue above):
VBScript: Here other parameters besides "-s" seem to ensure that the PC does not shut down; e.g.:
objShell.Run "shutdown /s /t " & iDlgSSdDelay & " /d P:0:0 /c """ & strComment & "'" & strBackup & "'."""

or
objShell.Run "shutdown /s /d P:0:0 /c """ & strComment & "'" & strBackup & "'."""        ' without /t xxx

PowerShell: It seems as if the 'PC-Shutdown' with original:
(Get-WMIObject Win32_OperatingSystem -ComputerName -EnableAllPrivileges).Win32Shutdown(8);

doesn't work at all; in any case, the PC makes no move to shut down.


Best regards, Joachim.

Edited 26 October 2020 11:50 AM by Joachim
Nick
Nick
Macrium Representative
Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)
Group: Administrators
Posts: 3.2K, Visits: 22K
Joachim - 25 October 2020 11:20 AM
Windows 10 Pro, x64, Version 2004, Build 19041.572; Hibernation 'On' - after 20 minutes.
Macrium Reflect, Version 7.3.5289, "Use the Macrium Task Scheduler"; Task-Environment: SYSTEM; Scheduler condition only: “Wake the computer to run this task”.

Hello,
I am using Reflect since v 7.1.xxxx. And I have automated my Backups with VBScript. After updating Reflect from v7.2.5107 to v7.3.5289 AND selecting recommended "Macrium Task Scheduler", my previous working Backup-Script will stopped during execution, because the OS enters the Hibernation-Mode.
Waking-up the PC (e.g. via Keyboard stroke) the script proceed running... until next hibernation.
This problem occurs under VBScript and PowerShell repeatable!

Workaround: Select "Use Windows Task Scheduler" and the same script works fine again - without hibernation / breaks.
Solving the problem fundamental: Make sure that a script, initiated and executed by Macrium Task Scheduler, is not interrupted by power saving modes such as hibernation, while it is running.

Details to the scripts:
My VBScript (the tested PowerShell-Script, too) was generated based to a Backup-definition as described.
Inside the Scripts-Main-Sections directly before "ExitCode = Backup (...)" an additional program runs like:
objShell.Run """C:\Program Files (x86)\<Path>\<Program.exe>"" /Read:""%ProgramFiles(x86)%\<Path>\<File.txt>"" /EventTextSelect:01 /NASon", 1, True
ExitCode = Backup (...)

This additional program looks if the NAS (Backup-target) is on, starts it if necessary, waits until NAS is ping able, waits some additional seconds until NAS can receive the Backup and writes an own detailed log file. This program (with 'wait'-Option) needs round about 5 minutes.
After / during executing this part of the whole backup script, the PC enters Hibernation and the script stops. (The script is continued after the wake-up.)

After executing the "ExitCode = Backup (...)" lines my additional Program starts again (with other parameters) and - in dependence on the results from first run - my NAS will be shutdown or...
This Program-call will take about 3 - 5 Minutes and after this, the next Hibernation occurs, before the PC-shutdown command is running.

To verify, if this is a (new) problem in VBScript, I created a PowerShell-Script with the same functionality and start my additional Program like:
Start-Process -FilePath $strRunAtStartApp -ArgumentList $strRunAtStartArgs -wait;
$iExitCode = Backup;

Under "Macrium Task Scheduler" it shows the same hibernation behaviours.
Selecting the "Use Windows Task Scheduler" this script also works fine, too.

IMPORTANT: To verify the hibernation issue with "Macrium Task Scheduler" it's sufficient to add a 'WScript.Sleep' instead of my 'additional Program' (see above) into the VBScript, like:
WScript.Sleep 360000 ' 6 minutes delay
' Do the backup
ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\ReflectBin.exe"" -e -w <BACKUP_TYPE> ""E:\Benutzer\<User>\Documents\Reflect\Test_2.xml"" -g")

Then start the script via "Scheduled Backups". The Hibernation modes occur within the '6 minutes delay'! (Possible, the script starts itself after the ‘6 minutes delay’.)


Supplement (not fully or individually tested due to lack of time):
VBScript: Here other parameters besides "-s" seem to ensure that the PC does not shut down; e.g.:
objShell.Run "shutdown /s /t " & iDlgSSdDelay & " /d P:0:0 /c """ & strComment & "'" & strBackup & "'."""

or
objShell.Run "shutdown /s /d P:0:0 /c """ & strComment & "'" & strBackup & "'."""        ' without /t xxx

PowerShell: It seems as if the 'PC-Shutdown' with original:
(Get-WMIObject Win32_OperatingSystem -ComputerName -EnableAllPrivileges).Win32Shutdown(8);

doesn't work at all; in any case, the PC makes no move to shut down.


Best regards, Joachim.

Hi Joachim

Thanks for posting and for bringing this to our attention. We will investigate and resolve for the next update.

Kind Regards

Nick

Macrium Support

Next Webinar

See our reviews on

Trustpilot Logo
Trustpilot Stars


Joachim
Joachim
Junior Member
Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)
Group: Forum Members
Posts: 42, Visits: 66
Hello Nick, thanks for the quick reply.
Regarding the above topic, here are a few brief experiences from a laptop with the same problem but possible in a slightly different form.

Windows 10 Pro, Version 2004, Build 19041.572 /
Macrium Reflect v7.3.5289, "Use the Macrium Task Scheduler" / Scheduled Backups as SYSTEM / Running from Admin-Account / Energy saving mode (Main operation): Screen: 30 minutes, Idle state: 1 hour.

VBScript:

'******************************************************************************
'*
'*
'* Module Name: Test2.vbs
'*
'* Abstract: This is a template VB Script file generated by Reflect v6
'* Modify to add your own functionality if required
'*
'*
'******************************************************************************

OPTION EXPLICIT

' call the main function
Call VBMain()


'******************************************************************************
'* Sub: VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input: None
'*
'* Output: None
'*
'******************************************************************************
Sub VBMain()
    Dim objShell
    Dim ExitCode

    Set objShell = WScript.CreateObject("WScript.Shell")

    WScript.Sleep 390000    ' 6:30 minutes

' Do the backup
    ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\ReflectBin.exe"" -e -w <BACKUP_TYPE> ""E:\Benutzer\JoAdmin\Documents\Reflect\My Backup.xml"" -g")

' Issue shutdown command
    objShell.Run "shutdown -s"

' done
    Set objShell = nothing
    wscript.quit(ExitCode)
End Sub


'******************************************************************************
'* Function: Backup
'*
'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
'*
'* Input: strCmdLine Command Line Arguments
'* Output: Exit Code
'*
'******************************************************************************
Function Backup(Byref strCmdLine)
    Dim objShell
    Dim objExecObject
    Dim iReturnCode

    strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)

' Run the backup or image
    Set objShell = WScript.CreateObject("WScript.Shell")
    iReturnCode = objShell.Run(strCmdLine, 1, true)

    if iReturnCode = 2 then
' Handle XML validation error

    elseif iReturnCode = 1 then
' Handle backup error
    elseif iReturnCode = 0 then
' Everything OK
    end if
    Backup = iReturnCode
    Set objShell = nothing
End Function

'******************************************************************************
'* Function: GetBackupTypeParameter
'*
'* Purpose: determines the backup type from command line parameter
'* -full Full backup
'* -inc Incremental backup
'* -diff Differential backup
'*
'* Input: None
'* Output: the parameter
'*
'******************************************************************************
Function GetBackupTypeParameter
    Dim i

    for i = 0 to Wscript.Arguments.Count - 1
     If Wscript.Arguments(i) = "-full" OR _
     Wscript.Arguments(i) = "-inc" OR _
     Wscript.Arguments(i) = "-diff" Then
     GetBackupTypeParameter = Wscript.Arguments(i)
     Exit Function
     End If
    Next

    GetBackupTypeParameter = ""

End Function


Running this script ("Test2.vbs") above via Scheduled Backups, see screenshots (> 20:20):
(The full Image backup has ~100 MB, target: local Harddisk.)

At >20:20:


At ~20:26 / 20:27, Reflect Massage:


At ~20:27: Reflect Message (Backup success):

but really it’s a Shutdown instead of Hibernation (because the Power-LED doesn’t flash).

At ~20:29 the laptop starts by itself.
After logging in as administrator: Windows message: "You will be logoff shortly." („Sie werden in Kürze abgemeldet.“). This may be the „shutdown -s“ from the Backup Script „Test2.vbs“ and the Laptop shuts down.
(If restarting the Laptop manually between ~20:27 and ~20:29 then the procedure is the same as described ‘at 20:29’ above.)

Sometimes it is possible to see a Windows dialog “Lock” (“Sperren”) at ~20:27 instead of the ‘Hibernation Screenshot’ (~20:27) above.

Hope this information helps instead of creating confusion ;-).

Best regards.

Nick
Nick
Macrium Representative
Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)
Group: Administrators
Posts: 3.2K, Visits: 22K
Joachim - 26 October 2020 8:38 PM
Hello Nick, thanks for the quick reply.
Regarding the above topic, here are a few brief experiences from a laptop with the same problem but possible in a slightly different form.

Windows 10 Pro, Version 2004, Build 19041.572 /
Macrium Reflect v7.3.5289, "Use the Macrium Task Scheduler" / Scheduled Backups as SYSTEM / Running from Admin-Account / Energy saving mode (Main operation): Screen: 30 minutes, Idle state: 1 hour.

VBScript:

'******************************************************************************
'*
'*
'* Module Name: Test2.vbs
'*
'* Abstract: This is a template VB Script file generated by Reflect v6
'* Modify to add your own functionality if required
'*
'*
'******************************************************************************

OPTION EXPLICIT

' call the main function
Call VBMain()


'******************************************************************************
'* Sub: VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input: None
'*
'* Output: None
'*
'******************************************************************************
Sub VBMain()
    Dim objShell
    Dim ExitCode

    Set objShell = WScript.CreateObject("WScript.Shell")

    WScript.Sleep 390000    ' 6:30 minutes

' Do the backup
    ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\ReflectBin.exe"" -e -w <BACKUP_TYPE> ""E:\Benutzer\JoAdmin\Documents\Reflect\My Backup.xml"" -g")

' Issue shutdown command
    objShell.Run "shutdown -s"

' done
    Set objShell = nothing
    wscript.quit(ExitCode)
End Sub


'******************************************************************************
'* Function: Backup
'*
'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
'*
'* Input: strCmdLine Command Line Arguments
'* Output: Exit Code
'*
'******************************************************************************
Function Backup(Byref strCmdLine)
    Dim objShell
    Dim objExecObject
    Dim iReturnCode

    strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)

' Run the backup or image
    Set objShell = WScript.CreateObject("WScript.Shell")
    iReturnCode = objShell.Run(strCmdLine, 1, true)

    if iReturnCode = 2 then
' Handle XML validation error

    elseif iReturnCode = 1 then
' Handle backup error
    elseif iReturnCode = 0 then
' Everything OK
    end if
    Backup = iReturnCode
    Set objShell = nothing
End Function

'******************************************************************************
'* Function: GetBackupTypeParameter
'*
'* Purpose: determines the backup type from command line parameter
'* -full Full backup
'* -inc Incremental backup
'* -diff Differential backup
'*
'* Input: None
'* Output: the parameter
'*
'******************************************************************************
Function GetBackupTypeParameter
    Dim i

    for i = 0 to Wscript.Arguments.Count - 1
     If Wscript.Arguments(i) = "-full" OR _
     Wscript.Arguments(i) = "-inc" OR _
     Wscript.Arguments(i) = "-diff" Then
     GetBackupTypeParameter = Wscript.Arguments(i)
     Exit Function
     End If
    Next

    GetBackupTypeParameter = ""

End Function


Running this script ("Test2.vbs") above via Scheduled Backups, see screenshots (> 20:20):
(The full Image backup has ~100 MB, target: local Harddisk.)

At >20:20:


At ~20:26 / 20:27, Reflect Massage:


At ~20:27: Reflect Message (Backup success):

but really it’s a Shutdown instead of Hibernation (because the Power-LED doesn’t flash).

At ~20:29 the laptop starts by itself.
After logging in as administrator: Windows message: "You will be logoff shortly." („Sie werden in Kürze abgemeldet.“). This may be the „shutdown -s“ from the Backup Script „Test2.vbs“ and the Laptop shuts down.
(If restarting the Laptop manually between ~20:27 and ~20:29 then the procedure is the same as described ‘at 20:29’ above.)

Sometimes it is possible to see a Windows dialog “Lock” (“Sperren”) at ~20:27 instead of the ‘Hibernation Screenshot’ (~20:27) above.

Hope this information helps instead of creating confusion ;-).

Best regards.

Hi Joachim

Thanks for getting back. Unless I've misunderstood, it appears that you have configured the backup to hibernate and immediately followed that with a shutdown in the VBScript source. This will cause the shutdown to be issued as the PC was entering hibernation state. Shutdown would then resume once the PC was woken from hibernation. Was that your intention?

You should either only use the VBScript to issue power state/shutdown commands or, preferably, do this in the backup advanced settings. 

If you right click on your backup definition, select 'Advanced Properties' > 'Shutdown' do you have 'Hibernation' selected?



 

Kind Regards

Nick

Macrium Support

Next Webinar

See our reviews on

Trustpilot Logo
Trustpilot Stars


Joachim
Joachim
Junior Member
Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)
Group: Forum Members
Posts: 42, Visits: 66
Hello Nick,

good idea. With my second post from yesterday evening „Laptop-Post“ you are right:
"Shutdown with Hibernation" under "Backup Definition Files", "Advanced Properties" was actually activated. I wonder why, because this option is disabled in all of my other / older scripts and I don't remember having it enabled explicitly. Because I always used the option "Reflect Defaults", "Scripts", "Enable Shut Down" for my scripts.
But shouldn't the Hibernation state only begin here when the script has been completely processed?

Since the mentioned option "Shutdown with Hibernation" under "Backup Definition Files", "Advanced Properties" - especially with regard to my first post - are definitely completely deactivated, the problem there remains, which does not change anything about my first post.

Sorry for the confusion regarding my second post (from yesterday).

Best regards.

Nick
Nick
Macrium Representative
Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)
Group: Administrators
Posts: 3.2K, Visits: 22K
Joachim - 27 October 2020 9:34 AM
Hello Nick,

good idea. With my second post from yesterday evening „Laptop-Post“ you are right:
"Shutdown with Hibernation" under "Backup Definition Files", "Advanced Properties" was actually activated. I wonder why, because this option is disabled in all of my other / older scripts and I don't remember having it enabled explicitly. Because I always used the option "Reflect Defaults", "Scripts", "Enable Shut Down" for my scripts.
But shouldn't the Hibernation state only begin here when the script has been completely processed?

Since the mentioned option "Shutdown with Hibernation" under "Backup Definition Files", "Advanced Properties" - especially with regard to my first post - are definitely completely deactivated, the problem there remains, which does not change anything about my first post.

Sorry for the confusion regarding my second post (from yesterday).

Best regards.

Thanks for getting back.

The 'Shutdown' option in the backup definition executes in the backup process has no knowledge of, and doesn't interact with, any calling scripts or processes. For this reason, shutdown options should only be set in the script or in the backup settings, never both.

With regard to handling power saving options from external sources, such as power schemes invoking hibernate or hybrid sleep, Reflect sets its thread execution level to ES_SYSTEM_REQUIRED which prevents sleep & hibernation while a backup is running. It then returns it to ES_CONTINUOUS (Normal) prior to executing any power saving options set for the backup. The calling process, in the case of a scripts, cannot set itself to prevent hibernate or hybrid sleep by changing the scheduler, otherwise this would prevent the entire script and it's sub processes from entering power saving and would stop the backup from initiating its own 'Shutdown' options in the backup def.

If you have seen the WTS disallowing sleep/hibernation in a scheduled script, then I'm afraid this is incorrect behavior as it will prevent the backup definition from actioning the Power option set for the definition. MTS is handling it correctly.

So, could you modify your VBScript with just two additional lines to disable hibernation before your NAS ping loop and enable it afterwards, and let us know if this resolves the issue?


   ' top of main code
   objShell.Exec("c:\windows\system32\powercfg.exe /h off")
   '
   '  your NAS ping loop or any other process
   '
   objShell.Exec("c:\windows\system32\powercfg.exe /h on")
   '
   ' start the backup
   ' or the above could go at the end of the script
   ' if there's no power saving options set in the backup
   '


EDIT:  If your PC has a 'Sleep' power setting in use, as well as 'Hibernate' then you'll need to add 2 more lines:


 ' to disable sleep
 objShell.Exec("c:\windows\system32\powercfg.exe /change standby-timeout-dc 0")
 ' enable sleep. change '5' for the number of minutes in your power config
 objShell.Exec("c:\windows\system32\powercfg.exe /change standby-timeout-dc 5")




Kind Regards

Nick

Macrium Support

Next Webinar

See our reviews on

Trustpilot Logo
Trustpilot Stars


Edited 27 October 2020 2:48 PM by Nick
Joachim
Joachim
Junior Member
Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)
Group: Forum Members
Posts: 42, Visits: 66
Hello Nick,

thank you for your comments - I don't want to leave an answer open.

First of all, it is clear that options such as 'hibernation' etc. should only be specified in one place. If your remarks refer to the "Backup Definition Files" / "Advanced Settings", the "Shutdown" option on my laptop that was activated there was a bit strange - but I already said that.
But my first post relates to my desktop - and here this option is completely deselected for all scripts.

Let's move away from the laptop to my productive system.
To your justified idea that the hibernation problem could be due to my script or the execution of the 'additional program' (NAS on / off etc.), I had already pointed out under IMPORTANT (see my first post here) that a WScript.Sleep is sufficient for error verification; instead of running my 'additional program'.
Plus the note that my script works with the "Windows Task Scheduler" (WTS) without any problems, ie without the hibernation problem; according to my own logs since 2018.
Hence the mention of my “workaround”.

In other words: the problem I described in the first post only occurs with the “Macrium Task Scheduler” (MTS); tested exclusively under Reflect v7.3.5289.
And this script definitely has no 'Shutdown' settings under "Backup Definition Files" / "Advanced Properties".

Nevertheless, yesterday I started to take up your ideas and test them further - with this script:

'******************************************************************************
'*
'*
'* Module Name:  Test_2.vbs
'*
'* Abstract:   This is a template VB Script file generated by Reflect v6
'*      Modify to add your own functionality if required
'*
'*
'******************************************************************************

OPTION EXPLICIT

' call the main function
Call VBMain()


'******************************************************************************
'* Sub:  VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input: None
'*
'* Output: None
'*
'******************************************************************************
Sub VBMain()
    Dim objShell
    Dim ExitCode

    Set objShell = WScript.CreateObject("WScript.Shell")

 ' top of main code
'   objShell.Exec("c:\windows\system32\powercfg.exe /h off")
 '
 ' your NAS ping loop or any other process
 '

    WScript.Sleep 360000    ' 6 minutes

' Do the backup
    ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\ReflectBin.exe"" -e -w <BACKUP_TYPE> ""E:\Benutzer\<User>\Documents\Reflect\Test_2.xml"" -g")

    WScript.Sleep 300000    ' 5 minutes

'   objShell.Exec("c:\windows\system32\powercfg.exe /h on")
 '
 ' start the backup
 ' or the above could go at the end of the script
 ' if there's no power saving options set in the backup
 '

' Issue shutdown command
    objShell.Run "shutdown -s"

' done
    Set objShell = nothing
    wscript.quit(ExitCode)
End Sub


'******************************************************************************
'* Function: Backup
'*
'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
'*
'* Input:  strCmdLine Command Line Arguments
'* Output: Exit Code
'*
'******************************************************************************
Function Backup(Byref strCmdLine)
    Dim objShell
    Dim objExecObject
    Dim iReturnCode

    strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)

' Run the backup or image
    Set objShell = WScript.CreateObject("WScript.Shell")
    iReturnCode = objShell.Run(strCmdLine, 1, true)

    if iReturnCode = 2 then
' Handle XML validation error

    elseif iReturnCode = 1 then
' Handle backup error
    elseif iReturnCode = 0 then
' Everything OK
    end if
    Backup = iReturnCode
    Set objShell = nothing
End Function

'******************************************************************************
'* Function: GetBackupTypeParameter
'*
'* Purpose: determines the backup type from command line parameter
'*    -full Full backup
'*    -inc Incremental backup
'*    -diff Differential backup
'*
'* Input:  None
'* Output: the parameter
'*
'******************************************************************************
Function GetBackupTypeParameter
    Dim i

    for i = 0 to Wscript.Arguments.Count - 1
      If Wscript.Arguments(i) = "-full" OR _
       Wscript.Arguments(i) = "-inc" OR _
       Wscript.Arguments(i) = "-diff" Then
       GetBackupTypeParameter = Wscript.Arguments(i)
       Exit Function
      End If
    Next

    GetBackupTypeParameter = ""

End Function


Note: The backup itself takes about 12 seconds (500 MB local backup), the WScript.Sleeps together delay about 11 minutes; the 'system' hibernation is still on 20 minutes.
I.e. the script is finished before 'system' hibernation occurs.

Out of 3 attempts yesterday, the error with the above script occurred 3 times under MTS.


For my 'normal' script of the daily backups, I can say that at least the incremental backups are also done within 20 minutes (= hibernation), as I can see from my own logs.

Here are two excerpts ...
First call starts at 19:20:02 (here switching on the NAS) ...
************************************************************************************************************************
Logfile from:         "NAS & Shares.exe" | v3.04.00 / 24.10.2018.
Parameters:           /Read:"C:\Program Files (x86)\MagicPacket\NAS & Shares - Backups.txt" /EventTextSelect:01 /NASon
Begin of Log:         15.10.2020 19:20:02 | KW: 42, Donnerstag.
========================================================================================================================
15.10.2020 19:20:02:     Programm-Start...
15.10.2020 19:20:08:     NAS '"DS"' war ausgeschaltet.
15.10.2020 19:20:08:     NAS '"DS"' starten (WoL-Versuch 1 von max. 1):
            '"C:\Program Files (x86)\MagicPacket\MagicPacket.exe" -silent -fav "DS 716+"'
            wird ausgeführt ( 3 Sekunden nach Programm-Start)...
15.10.2020 19:20:08:     NAS '"DS"' starten (WoL-Versuch 1 von max. 1) wurde ausgeführt.
            ('"C:\Program Files (x86)\MagicPacket\MagicPacket.exe" -silent -fav "DS 716+"').
15.10.2020 19:20:21:     "DS" per 'ping' noch nicht erreichbar: ••••••
15.10.2020 19:25:46:     "DS" per 'ping' erreichbar.
            (Benötigte Versuche (WoL: 1/ 1): ges. 7 Ping(s) in 91 Sek. (max. > 360 Sek.)
            Programm-Laufzeit: 344 Sekunden inkl. 240 Sekunden warten
            bis NAS komplett 'hochgefahren' (online) ist.
15.10.2020 19:25:46:     Programm-Ende, fehlerfrei (Err-Code: 0) nach 344 Sekunden.
========================================================================================================================
End of Log:         15.10.2020 19:25:46 | KW: 42, Donnerstag.
************************************************************************************************************************


According to the Reflect protocol, the actual backup "ExitCode = Backup (...)" started at 19:26:25;
the second backup specified in the script at 19:29:47.

Afterwards the second call started at 19:30:49 (here switching off the NAS) ...
************************************************************************************************************************
Logfile from:         "NAS & Shares.exe" | v3.04.00 / 24.10.2018.
Parameters:           /Read:"C:\Program Files (x86)\MagicPacket\NAS & Shares - Backups.txt" /EventTextSelect:01 /RemoveDLs
Begin of Log:         15.10.2020 19:30:49 | KW: 42, Donnerstag.
========================================================================================================================
15.10.2020 19:30:49:     Programm-Start...
15.10.2020 19:33:19:     NAS "DS" wurde erfolgreich herunterfahren.
            ('"C:\Program Files (x86)\MagicPacket\<Programm>" <Parameter>').
            (Time: 141 [sec].)
15.10.2020 19:33:19:     Programm-Ende, fehlerfrei (Err-Code: 0) nach 149 Sekunden.
========================================================================================================================
End of Log:         15.10.2020 19:33:19 | KW: 42, Donnerstag.
************************************************************************************************************************

and ended at 19:33:19. Then the script “shutdown –s” was executed. Total duration <15 minutes.}

Newer logs are currently no longer available ...
Since I was testing late in the afternoon yesterday and switched several times from MTS to WTS to test your ideas regarding "powercfg.exe / h off" etc., I had to go back to WTS - for the purpose of my normal backup. My normal script started, the NAS was switched on, but no further execution of the script afterwards.
After logging in, the PC still worked, but no reactions from Reflect (not even the Reflect window responded), so I restored my last backup with Reflect v7.2.5107 because I was working on my productive system. (This is why there are no newer logs available (v7.3.5289).)

If I can think of something else and / or I don't need my laptop, I might try it again when I get the chance.
But then as a precaution under Windows 10, 20H2. Because, as I mentioned in the first post, the shutdown command works (under PowerShell):

(Get-WMIObject Win32_OperatingSystem -ComputerName '.' -EnableAllPrivileges) .Win32Shutdown (8);

not either. Therefore I could imagine that ES_SYSTEM_REQUIRED and ES_CONTINUOUS could also have difficulties.

So for the time being I will stay with v7.2.5107.

Best regards.


Nick
Nick
Macrium Representative
Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)
Group: Administrators
Posts: 3.2K, Visits: 22K
Joachim - 29 October 2020 11:17 AM
Hello Nick,

thank you for your comments - I don't want to leave an answer open.

First of all, it is clear that options such as 'hibernation' etc. should only be specified in one place. If your remarks refer to the "Backup Definition Files" / "Advanced Settings", the "Shutdown" option on my laptop that was activated there was a bit strange - but I already said that.
But my first post relates to my desktop - and here this option is completely deselected for all scripts.

Let's move away from the laptop to my productive system.
To your justified idea that the hibernation problem could be due to my script or the execution of the 'additional program' (NAS on / off etc.), I had already pointed out under IMPORTANT (see my first post here) that a WScript.Sleep is sufficient for error verification; instead of running my 'additional program'.
Plus the note that my script works with the "Windows Task Scheduler" (WTS) without any problems, ie without the hibernation problem; according to my own logs since 2018.
Hence the mention of my “workaround”.

In other words: the problem I described in the first post only occurs with the “Macrium Task Scheduler” (MTS); tested exclusively under Reflect v7.3.5289.
And this script definitely has no 'Shutdown' settings under "Backup Definition Files" / "Advanced Properties".

Nevertheless, yesterday I started to take up your ideas and test them further - with this script:

'******************************************************************************
'*
'*
'* Module Name:  Test_2.vbs
'*
'* Abstract:   This is a template VB Script file generated by Reflect v6
'*      Modify to add your own functionality if required
'*
'*
'******************************************************************************

OPTION EXPLICIT

' call the main function
Call VBMain()


'******************************************************************************
'* Sub:  VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input: None
'*
'* Output: None
'*
'******************************************************************************
Sub VBMain()
    Dim objShell
    Dim ExitCode

    Set objShell = WScript.CreateObject("WScript.Shell")

 ' top of main code
'   objShell.Exec("c:\windows\system32\powercfg.exe /h off")
 '
 ' your NAS ping loop or any other process
 '

    WScript.Sleep 360000    ' 6 minutes

' Do the backup
    ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\ReflectBin.exe"" -e -w <BACKUP_TYPE> ""E:\Benutzer\<User>\Documents\Reflect\Test_2.xml"" -g")

    WScript.Sleep 300000    ' 5 minutes

'   objShell.Exec("c:\windows\system32\powercfg.exe /h on")
 '
 ' start the backup
 ' or the above could go at the end of the script
 ' if there's no power saving options set in the backup
 '

' Issue shutdown command
    objShell.Run "shutdown -s"

' done
    Set objShell = nothing
    wscript.quit(ExitCode)
End Sub


'******************************************************************************
'* Function: Backup
'*
'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
'*
'* Input:  strCmdLine Command Line Arguments
'* Output: Exit Code
'*
'******************************************************************************
Function Backup(Byref strCmdLine)
    Dim objShell
    Dim objExecObject
    Dim iReturnCode

    strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)

' Run the backup or image
    Set objShell = WScript.CreateObject("WScript.Shell")
    iReturnCode = objShell.Run(strCmdLine, 1, true)

    if iReturnCode = 2 then
' Handle XML validation error

    elseif iReturnCode = 1 then
' Handle backup error
    elseif iReturnCode = 0 then
' Everything OK
    end if
    Backup = iReturnCode
    Set objShell = nothing
End Function

'******************************************************************************
'* Function: GetBackupTypeParameter
'*
'* Purpose: determines the backup type from command line parameter
'*    -full Full backup
'*    -inc Incremental backup
'*    -diff Differential backup
'*
'* Input:  None
'* Output: the parameter
'*
'******************************************************************************
Function GetBackupTypeParameter
    Dim i

    for i = 0 to Wscript.Arguments.Count - 1
      If Wscript.Arguments(i) = "-full" OR _
       Wscript.Arguments(i) = "-inc" OR _
       Wscript.Arguments(i) = "-diff" Then
       GetBackupTypeParameter = Wscript.Arguments(i)
       Exit Function
      End If
    Next

    GetBackupTypeParameter = ""

End Function


Note: The backup itself takes about 12 seconds (500 MB local backup), the WScript.Sleeps together delay about 11 minutes; the 'system' hibernation is still on 20 minutes.
I.e. the script is finished before 'system' hibernation occurs.

Out of 3 attempts yesterday, the error with the above script occurred 3 times under MTS.


For my 'normal' script of the daily backups, I can say that at least the incremental backups are also done within 20 minutes (= hibernation), as I can see from my own logs.

Here are two excerpts ...
First call starts at 19:20:02 (here switching on the NAS) ...
************************************************************************************************************************
Logfile from:         "NAS & Shares.exe" | v3.04.00 / 24.10.2018.
Parameters:           /Read:"C:\Program Files (x86)\MagicPacket\NAS & Shares - Backups.txt" /EventTextSelect:01 /NASon
Begin of Log:         15.10.2020 19:20:02 | KW: 42, Donnerstag.
========================================================================================================================
15.10.2020 19:20:02:     Programm-Start...
15.10.2020 19:20:08:     NAS '"DS"' war ausgeschaltet.
15.10.2020 19:20:08:     NAS '"DS"' starten (WoL-Versuch 1 von max. 1):
            '"C:\Program Files (x86)\MagicPacket\MagicPacket.exe" -silent -fav "DS 716+"'
            wird ausgeführt ( 3 Sekunden nach Programm-Start)...
15.10.2020 19:20:08:     NAS '"DS"' starten (WoL-Versuch 1 von max. 1) wurde ausgeführt.
            ('"C:\Program Files (x86)\MagicPacket\MagicPacket.exe" -silent -fav "DS 716+"').
15.10.2020 19:20:21:     "DS" per 'ping' noch nicht erreichbar: ••••••
15.10.2020 19:25:46:     "DS" per 'ping' erreichbar.
            (Benötigte Versuche (WoL: 1/ 1): ges. 7 Ping(s) in 91 Sek. (max. > 360 Sek.)
            Programm-Laufzeit: 344 Sekunden inkl. 240 Sekunden warten
            bis NAS komplett 'hochgefahren' (online) ist.
15.10.2020 19:25:46:     Programm-Ende, fehlerfrei (Err-Code: 0) nach 344 Sekunden.
========================================================================================================================
End of Log:         15.10.2020 19:25:46 | KW: 42, Donnerstag.
************************************************************************************************************************


According to the Reflect protocol, the actual backup "ExitCode = Backup (...)" started at 19:26:25;
the second backup specified in the script at 19:29:47.

Afterwards the second call started at 19:30:49 (here switching off the NAS) ...
************************************************************************************************************************
Logfile from:         "NAS & Shares.exe" | v3.04.00 / 24.10.2018.
Parameters:           /Read:"C:\Program Files (x86)\MagicPacket\NAS & Shares - Backups.txt" /EventTextSelect:01 /RemoveDLs
Begin of Log:         15.10.2020 19:30:49 | KW: 42, Donnerstag.
========================================================================================================================
15.10.2020 19:30:49:     Programm-Start...
15.10.2020 19:33:19:     NAS "DS" wurde erfolgreich herunterfahren.
            ('"C:\Program Files (x86)\MagicPacket\<Programm>" <Parameter>').
            (Time: 141 [sec].)
15.10.2020 19:33:19:     Programm-Ende, fehlerfrei (Err-Code: 0) nach 149 Sekunden.
========================================================================================================================
End of Log:         15.10.2020 19:33:19 | KW: 42, Donnerstag.
************************************************************************************************************************

and ended at 19:33:19. Then the script “shutdown –s” was executed. Total duration <15 minutes.}

Newer logs are currently no longer available ...
Since I was testing late in the afternoon yesterday and switched several times from MTS to WTS to test your ideas regarding "powercfg.exe / h off" etc., I had to go back to WTS - for the purpose of my normal backup. My normal script started, the NAS was switched on, but no further execution of the script afterwards.
After logging in, the PC still worked, but no reactions from Reflect (not even the Reflect window responded), so I restored my last backup with Reflect v7.2.5107 because I was working on my productive system. (This is why there are no newer logs available (v7.3.5289).)

If I can think of something else and / or I don't need my laptop, I might try it again when I get the chance.
But then as a precaution under Windows 10, 20H2. Because, as I mentioned in the first post, the shutdown command works (under PowerShell):

(Get-WMIObject Win32_OperatingSystem -ComputerName '.' -EnableAllPrivileges) .Win32Shutdown (8);

not either. Therefore I could imagine that ES_SYSTEM_REQUIRED and ES_CONTINUOUS could also have difficulties.

So for the time being I will stay with v7.2.5107.

Best regards.


Thanks for geting back.

Nevertheless, yesterday I started to take up your ideas and test them further - with this script:


'******************************************************************************
Sub VBMain()
  Dim objShell
  Dim ExitCode

  Set objShell = WScript.CreateObject("WScript.Shell")

' top of main code
'  objShell.Exec("c:\windows\system32\powercfg.exe /h off")
'
' your NAS ping loop or any other process
'

  WScript.Sleep 360000  ' 6 minutes

I can see from your code that the line "objShell.Exec("c:\windows\system32\powercfg.exe /h off")" is commented out and won't execute. I don't know whether it was in this state when you tested?

Kind Regards

Nick

Macrium Support

Next Webinar

See our reviews on

Trustpilot Logo
Trustpilot Stars


Nick
Nick
Macrium Representative
Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)Macrium Representative (5.4K reputation)
Group: Administrators
Posts: 3.2K, Visits: 22K
Nick - 29 October 2020 1:03 PM
Joachim - 29 October 2020 11:17 AM
Hello Nick,

thank you for your comments - I don't want to leave an answer open.

First of all, it is clear that options such as 'hibernation' etc. should only be specified in one place. If your remarks refer to the "Backup Definition Files" / "Advanced Settings", the "Shutdown" option on my laptop that was activated there was a bit strange - but I already said that.
But my first post relates to my desktop - and here this option is completely deselected for all scripts.

Let's move away from the laptop to my productive system.
To your justified idea that the hibernation problem could be due to my script or the execution of the 'additional program' (NAS on / off etc.), I had already pointed out under IMPORTANT (see my first post here) that a WScript.Sleep is sufficient for error verification; instead of running my 'additional program'.
Plus the note that my script works with the "Windows Task Scheduler" (WTS) without any problems, ie without the hibernation problem; according to my own logs since 2018.
Hence the mention of my “workaround”.

In other words: the problem I described in the first post only occurs with the “Macrium Task Scheduler” (MTS); tested exclusively under Reflect v7.3.5289.
And this script definitely has no 'Shutdown' settings under "Backup Definition Files" / "Advanced Properties".

Nevertheless, yesterday I started to take up your ideas and test them further - with this script:

'******************************************************************************
'*
'*
'* Module Name:  Test_2.vbs
'*
'* Abstract:   This is a template VB Script file generated by Reflect v6
'*      Modify to add your own functionality if required
'*
'*
'******************************************************************************

OPTION EXPLICIT

' call the main function
Call VBMain()


'******************************************************************************
'* Sub:  VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input: None
'*
'* Output: None
'*
'******************************************************************************
Sub VBMain()
    Dim objShell
    Dim ExitCode

    Set objShell = WScript.CreateObject("WScript.Shell")

 ' top of main code
'   objShell.Exec("c:\windows\system32\powercfg.exe /h off")
 '
 ' your NAS ping loop or any other process
 '

    WScript.Sleep 360000    ' 6 minutes

' Do the backup
    ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\ReflectBin.exe"" -e -w <BACKUP_TYPE> ""E:\Benutzer\<User>\Documents\Reflect\Test_2.xml"" -g")

    WScript.Sleep 300000    ' 5 minutes

'   objShell.Exec("c:\windows\system32\powercfg.exe /h on")
 '
 ' start the backup
 ' or the above could go at the end of the script
 ' if there's no power saving options set in the backup
 '

' Issue shutdown command
    objShell.Run "shutdown -s"

' done
    Set objShell = nothing
    wscript.quit(ExitCode)
End Sub


'******************************************************************************
'* Function: Backup
'*
'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
'*
'* Input:  strCmdLine Command Line Arguments
'* Output: Exit Code
'*
'******************************************************************************
Function Backup(Byref strCmdLine)
    Dim objShell
    Dim objExecObject
    Dim iReturnCode

    strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)

' Run the backup or image
    Set objShell = WScript.CreateObject("WScript.Shell")
    iReturnCode = objShell.Run(strCmdLine, 1, true)

    if iReturnCode = 2 then
' Handle XML validation error

    elseif iReturnCode = 1 then
' Handle backup error
    elseif iReturnCode = 0 then
' Everything OK
    end if
    Backup = iReturnCode
    Set objShell = nothing
End Function

'******************************************************************************
'* Function: GetBackupTypeParameter
'*
'* Purpose: determines the backup type from command line parameter
'*    -full Full backup
'*    -inc Incremental backup
'*    -diff Differential backup
'*
'* Input:  None
'* Output: the parameter
'*
'******************************************************************************
Function GetBackupTypeParameter
    Dim i

    for i = 0 to Wscript.Arguments.Count - 1
      If Wscript.Arguments(i) = "-full" OR _
       Wscript.Arguments(i) = "-inc" OR _
       Wscript.Arguments(i) = "-diff" Then
       GetBackupTypeParameter = Wscript.Arguments(i)
       Exit Function
      End If
    Next

    GetBackupTypeParameter = ""

End Function


Note: The backup itself takes about 12 seconds (500 MB local backup), the WScript.Sleeps together delay about 11 minutes; the 'system' hibernation is still on 20 minutes.
I.e. the script is finished before 'system' hibernation occurs.

Out of 3 attempts yesterday, the error with the above script occurred 3 times under MTS.


For my 'normal' script of the daily backups, I can say that at least the incremental backups are also done within 20 minutes (= hibernation), as I can see from my own logs.

Here are two excerpts ...
First call starts at 19:20:02 (here switching on the NAS) ...
************************************************************************************************************************
Logfile from:         "NAS & Shares.exe" | v3.04.00 / 24.10.2018.
Parameters:           /Read:"C:\Program Files (x86)\MagicPacket\NAS & Shares - Backups.txt" /EventTextSelect:01 /NASon
Begin of Log:         15.10.2020 19:20:02 | KW: 42, Donnerstag.
========================================================================================================================
15.10.2020 19:20:02:     Programm-Start...
15.10.2020 19:20:08:     NAS '"DS"' war ausgeschaltet.
15.10.2020 19:20:08:     NAS '"DS"' starten (WoL-Versuch 1 von max. 1):
            '"C:\Program Files (x86)\MagicPacket\MagicPacket.exe" -silent -fav "DS 716+"'
            wird ausgeführt ( 3 Sekunden nach Programm-Start)...
15.10.2020 19:20:08:     NAS '"DS"' starten (WoL-Versuch 1 von max. 1) wurde ausgeführt.
            ('"C:\Program Files (x86)\MagicPacket\MagicPacket.exe" -silent -fav "DS 716+"').
15.10.2020 19:20:21:     "DS" per 'ping' noch nicht erreichbar: ••••••
15.10.2020 19:25:46:     "DS" per 'ping' erreichbar.
            (Benötigte Versuche (WoL: 1/ 1): ges. 7 Ping(s) in 91 Sek. (max. > 360 Sek.)
            Programm-Laufzeit: 344 Sekunden inkl. 240 Sekunden warten
            bis NAS komplett 'hochgefahren' (online) ist.
15.10.2020 19:25:46:     Programm-Ende, fehlerfrei (Err-Code: 0) nach 344 Sekunden.
========================================================================================================================
End of Log:         15.10.2020 19:25:46 | KW: 42, Donnerstag.
************************************************************************************************************************


According to the Reflect protocol, the actual backup "ExitCode = Backup (...)" started at 19:26:25;
the second backup specified in the script at 19:29:47.

Afterwards the second call started at 19:30:49 (here switching off the NAS) ...
************************************************************************************************************************
Logfile from:         "NAS & Shares.exe" | v3.04.00 / 24.10.2018.
Parameters:           /Read:"C:\Program Files (x86)\MagicPacket\NAS & Shares - Backups.txt" /EventTextSelect:01 /RemoveDLs
Begin of Log:         15.10.2020 19:30:49 | KW: 42, Donnerstag.
========================================================================================================================
15.10.2020 19:30:49:     Programm-Start...
15.10.2020 19:33:19:     NAS "DS" wurde erfolgreich herunterfahren.
            ('"C:\Program Files (x86)\MagicPacket\<Programm>" <Parameter>').
            (Time: 141 [sec].)
15.10.2020 19:33:19:     Programm-Ende, fehlerfrei (Err-Code: 0) nach 149 Sekunden.
========================================================================================================================
End of Log:         15.10.2020 19:33:19 | KW: 42, Donnerstag.
************************************************************************************************************************

and ended at 19:33:19. Then the script “shutdown –s” was executed. Total duration <15 minutes.}

Newer logs are currently no longer available ...
Since I was testing late in the afternoon yesterday and switched several times from MTS to WTS to test your ideas regarding "powercfg.exe / h off" etc., I had to go back to WTS - for the purpose of my normal backup. My normal script started, the NAS was switched on, but no further execution of the script afterwards.
After logging in, the PC still worked, but no reactions from Reflect (not even the Reflect window responded), so I restored my last backup with Reflect v7.2.5107 because I was working on my productive system. (This is why there are no newer logs available (v7.3.5289).)

If I can think of something else and / or I don't need my laptop, I might try it again when I get the chance.
But then as a precaution under Windows 10, 20H2. Because, as I mentioned in the first post, the shutdown command works (under PowerShell):

(Get-WMIObject Win32_OperatingSystem -ComputerName '.' -EnableAllPrivileges) .Win32Shutdown (8);

not either. Therefore I could imagine that ES_SYSTEM_REQUIRED and ES_CONTINUOUS could also have difficulties.

So for the time being I will stay with v7.2.5107.

Best regards.


Thanks for geting back.

Nevertheless, yesterday I started to take up your ideas and test them further - with this script:


'******************************************************************************
Sub VBMain()
  Dim objShell
  Dim ExitCode

  Set objShell = WScript.CreateObject("WScript.Shell")

' top of main code
'  objShell.Exec("c:\windows\system32\powercfg.exe /h off")
'
' your NAS ping loop or any other process
'

  WScript.Sleep 360000  ' 6 minutes

I can see from your code that the line "objShell.Exec("c:\windows\system32\powercfg.exe /h off")" is commented out and won't execute. I don't know whether it was in this state when you tested?

As well as the commented out line mentioned above, please note the edit in my previous post as well:

If your PC has a 'Sleep' power setting in use, as well as 'Hibernate' then you'll need to add 2 more lines:


' to disable sleep
objShell.Exec("c:\windows\system32\powercfg.exe /change standby-timeout-dc 0")
' enable sleep. change '5' for the number of minutes in your power config
objShell.Exec("c:\windows\system32\powercfg.exe /change standby-timeout-dc 5")


Kind Regards

Nick

Macrium Support

Next Webinar

See our reviews on

Trustpilot Logo
Trustpilot Stars


Edited 29 October 2020 1:12 PM by Nick
Joachim
Joachim
Junior Member
Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)Junior Member (55 reputation)
Group: Forum Members
Posts: 42, Visits: 66
Hello Nick,
it is correct that the two "powercfg.exe /h off" and "powercfg.exe /h on" are commented out in the script copy.
But I wanted to test exactly this script again with the both “WScript.Sleep” commands, whether the error actually (still) occurs. That was the case.
In the next step I would, of course, have removed the ‘ in front of the two lines.
But there was no time for these tests last evening.



With regard to handling power saving options from external sources, such as power schemes invoking hibernate or hybrid sleep, Reflect sets its thread execution level to ES_SYSTEM_REQUIRED which prevents sleep & hibernation while a backup is running. It then returns it to ES_CONTINUOUS (Normal) prior to executing any power saving options set for the backup. The calling process, in the case of a scripts, cannot set itself to prevent hibernate or hybrid sleep by changing the scheduler, otherwise this would prevent the entire script and it's sub processes from entering power saving and would stop the backup from initiating its own ' Shutdown 'options in the backup def.

If you have seen the WTS disallowing sleep / hibernation in a scheduled script, then I'm afraid this is incorrect behavior as it will prevent the backup definition from actioning the power option set for the definition. MTS is handling it correctly.


If we don't misunderstand each other, I think that's not true.
In my opinion, the process that executes the script (<name> .vbs or <name> .ps1) must execute the

SetThreadExecutionState ($ES_CONTINUOUS –bor $ES_SYSTEM_REQUIRED)

and immediately after the end of execution

SetThreadExecutionState ($ES_CONTINUOUS)

to restore the previous state. From my point of view, the 'process executing the script' would be the respective scheduler. This would then have to run with a kind of “-wait” parameter until the called script was terminated. What I'm assuming, because the script exit code has to be evaluated before a “shutdown -s” is executed.

If I am not mistaken, the following script (from this source) can be used to observe that no energy-saving mode occurs during runtime (!) of this script. This should then also apply to subscripts that are executed by the backup script that is still running.

If my assumptions are correct, this would explain why the problem does not occur with the “Windows Task Scheduler” (WTS), but with the “Macrium Task Scheduler”.
So, I cannot see any “wrong behavior by the WTS”, which Reflect has been using for years.

#!/usr/bin/env powershell

# This script can keep the computer awake while executing another executable, or
# if no executable was passed in, then it stays awake until this script stops.
# There are 3 different ways of staying awake:
# Away Mode - Enable away mode (https://blogs.msdn.microsoft.com/david_fleischman/2005/10/21/what-does-away-mode-do-anyway/)
# Display Mode - Keep the display on and don't go to sleep or hibernation
# System Mode - Don't go to sleep or hibernation
# The default mode is the System Mode.
# Away mode is only available when away mode is enabled in the advanced power options.
# These commands are advisory, the option to allow programs to request to disable
# sleep or display off is in advanced power options.
# The above options will need to be first enabled in the registry before you can
# see them in the advanced power options.
# An alternative to this script is using presentation mode, but this is more flexible.

param (
[string]$Executable = $null,
[ValidateSet('Away', 'Display', 'System')]$Option = 'System'
)

$Code=@'
[DllImport("kernel32.dll", CharSet = CharSet.Auto,SetLastError = true)]
public static extern void SetThreadExecutionState(uint esFlags);
'@

$ste = Add-Type -memberDefinition $Code -name System -namespace Win32 -passThru

# Requests that the other EXECUTION_STATE flags set remain in effect until
# SetThreadExecutionState is called again with the ES_CONTINUOUS flag set and
# one of the other EXECUTION_STATE flags cleared.
$ES_CONTINUOUS = [uint32]"0x80000000"
$ES_AWAYMODE_REQUIRED = [uint32]"0x00000040"
$ES_DISPLAY_REQUIRED = [uint32]"0x00000002"
$ES_SYSTEM_REQUIRED = [uint32]"0x00000001"

Switch ($Option) {
"Away" {$Setting = $ES_AWAYMODE_REQUIRED}
"Display" {$Setting = $ES_DISPLAY_REQUIRED}
"System" {$Setting = $ES_SYSTEM_REQUIRED}
}

try {
Write-Host "Staying Awake with ``${Option}`` Option"
$ste::SetThreadExecutionState($ES_CONTINUOUS -bor $Setting)
if ($Executable) {
Write-Host "Executing Executable"
& "$Executable"
} else {
Read-Host "Enter or Exit to Stop Staying Awake"
}
} finally {
Write-Host "Stopping Staying Awake"
$ste::SetThreadExecutionState($ES_CONTINUOUS)
}


Best regards.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Login

Explore
Messages
Mentions
Search