Checkpoint-Computer hangs sometimes

asked 2020-09-01T21:42:46.367+00:00
noel lapin 306 Reputation points

Checkpoint-Computer is a command to make a restore point in PowerShell script.
Sometimes it repeats "99% Completed" for hours.
Does anyone know the cause?

Quick remedy: Making it manually with the Control Panel.
Not using a script, it always succeeds.
But I hope to make restore points automatically.

---
I did chkdsk, dism, sfc, stopped anti-virus, erased restore points and shadow copies,
tried PowerShell ISE and Visual Studio Code, but couldn't get any hint.
So I made the files below, but it does not solve the problem.
Also, I think there should be shorter methods to produce the same result.

[ _RestorePoint.bat ]
@set "this=%0%"
@Jason Li "([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
  [Security.Principal.WindowsBuiltInRole]::Administrator)" | find /i "True" > nul
@if ErrorLevel 1 (
  echo not admin, %this% will exit
  exit
)

set /a "loop_count=0"
:label_loop
set /a "loop_count=%loop_count% + 1"
@if %loop_count% gtr 3 (
  echo time up, when it fails, it fails
  goto label_end
)

PowerShell C:\tmp\_RestoreDate.ps1 | find /i "new"
if %ErrorLevel% equ 0 goto label_end

Reg import C:\tmp\_PermitRestoreTime.reg
taskkill /f /fi "ImageName eq PowerShell.exe"
  /fi "WindowTitle eq Administrator: CreatingRestorePoint"
start "CreatingRestorePoint" /RealTime PowerShell -ExecutionPolicy Unrestricted
  -OutputFormat XML -WindowStyle Minimized
  -Command " Checkpoint-Computer -Description 'daily'
    -RestorePointType 'MODIFY_SETTINGS' "
timeout 1500 > nul
taskkill /f /fi "ImageName eq PowerShell.exe"
  /fi "WindowTitle eq Administrator: CreatingRestorePoint"
goto label_loop

:label_end
PowerShell Get-ComputerRestorePoint
exit
[eof]

[ _RestoreDate.ps1 ]
$currentUser = New-Object Security.Principal.WindowsPrincipal $( [Security.Principal.WindowsIdentity]::GetCurrent() )
$testResult = $currentUser.IsInRole( [Security.Principal.WindowsBuiltinRole]::Administrator )
If ( $testResult -eq $False ) {
  echo "not admin"
  Exit
}

$targetTime = (Get-Date).AddMinutes( -30 )
$ts = $targetTime.ToString( "MM/dd/yyyy HH:mm" )

$a = Get-ComputerRestorePoint | Select-Object CreationTime
ForEach ( $b in $a ) {
  $c = $b.CreationTime
  $d = $c.ToString()
  $e = $d.SubString( 0, 14 )
  $f = $e + '-00:00' #using local time not utc
  $g = [DateTime]::ParseExact( $f, 'yyyyMMddHHmmsszzz', $null )
  $gs = $g.ToString( "MM/dd/yyyy HH:mm" )
  if ( $g -gt $targetTime ) {
    Write-Output $( 'new restore point:' + $gs + ' > now - 30min:' + $ts )
  } else {
    Write-Output $( 'old restore point:' + $gs + ' <= now - 30min:' + $ts )
  }
}
[eof]

[ _PermitRestoreTime.reg ]
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore]
"SystemRestorePointCreationFrequency"=dword:00000001
[eof]

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
5,919 questions
{count} votes

Accepted answer
  1. answered 2020-10-09T02:15:28.727+00:00
    noel lapin 306 Reputation points

    wmic.exe /NameSpace:\root\default Path SystemRestore Call CreateRestorePoint "wmic",100,7

    This has worked for these 10 days without sticking.

    Great thanks to IanXue-MSFT and Castorix31.

    No comments

0 additional answers

Sort by: Most helpful