Skip to content

Instantly share code, notes, and snippets.

@logchan
Created February 24, 2019 16:41
Show Gist options
  • Save logchan/3f9762291c2c93193e0d94d2d5cbcae6 to your computer and use it in GitHub Desktop.
Save logchan/3f9762291c2c93193e0d94d2d5cbcae6 to your computer and use it in GitHub Desktop.
Remove the "Move to OneDrive" context menu item permanently by clearing the values of the registry keys and denying access.
#Requires -RunAsAdministrator
New-PSDrive -Name HKCR_RMTO -PSProvider Registry -Root 'HKEY_CLASSES_ROOT'
pushd HKCR_RMTO:
$keys = '*\shellex\ContextMenuHandlers\ FileSyncEx', 'Directory\Background\shellex\ContextMenuHandlers\ FileSyncEx', 'Directory\shellex\ContextMenuHandlers\ FileSyncEx', 'IE.AssocFile.URL\shellex\ContextMenuHandlers\ FileSyncEx', 'lnkfile\shellex\ContextMenuHandlers\ FileSyncEx'
$rights = 'ChangePermissions', 'CreateSubKey', 'Delete', 'FullControl', 'SetValue', 'TakeOwnership', 'WriteKey'
foreach ($key in $keys) {
REG DELETE "HKEY_CLASSES_ROOT\$key" /ve /f
$reg = "\$key"
$acl = Get-Acl -LiteralPath $reg
foreach ($right in $rights) {
$rule = New-Object System.Security.AccessControl.RegistryAccessRule("everyone",$right,"Deny")
$acl.AddAccessRule($rule)
}
$acl | Format-List
Set-Acl -LiteralPath $reg -AclObject $acl
}
popd
Remove-PSDrive -Name HKCR_RMTO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment