-
-
Save tranphuquy19/24faf09c097358049b92b6afb9390546 to your computer and use it in GitHub Desktop.
Disable Windows 10 Update Restart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$task = Get-ScheduledTask | Where-Object ` | |
{ ` | |
$_.TaskPath -eq "\Microsoft\Windows\UpdateOrchestrator\" -and ` | |
$_.TaskName -eq "Reboot" ` | |
} | |
$task_file = "C:\Windows\System32\Tasks\Microsoft\Windows\UpdateOrchestrator\Reboot" | |
if( $task -eq $null ) | |
{ | |
echo "Task not found" | |
exit | |
} | |
$task_state = $( $task |Select State ).State | |
echo "STATE: $task_state" | |
if( $task_state -ne "Disabled" ) | |
{ | |
echo "Disabling" | |
$task | Disable-ScheduledTask |out-null | |
echo "Locking Modifications" | |
#disabling permission inheritance | |
$acl = Get-Acl -Path $task_file | |
$acl.SetAccessRuleProtection($true, $true) | |
Set-Acl -Path $task_file -AclObject $acl | |
#limiting all permissions to read / read+execute | |
$acl = Get-Acl -Path $task_file | |
$inheritance = [System.Security.AccessControl.InheritanceFlags]::None | |
$propagation = [System.Security.AccessControl.PropagationFlags]::None | |
$accesscontrol =[System.Security.AccessControl.AccessControlType]::Allow | |
ForEach( $rule in $acl.Access ) | |
{ | |
$account = New-Object System.Security.Principal.NTAccount( $rule.IdentityReference ) | |
$permissions = [System.Security.AccessControl.FileSystemRights]"ChangePermissions, Delete, DeleteSubdirectoriesAndFiles, TakeOwnership, Write" | |
$fsar = New-Object system.security.AccessControl.FileSystemAccessRule( $account, $permissions, $inheritance, $propagation, $accesscontrol ) | |
$acl.RemoveAccessRule( $fsar ) |out-null | |
} | |
Set-Acl -Path $task_file -AclObject $acl | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment