W4RH4WK / Debloat-Windows-10

A Collection of Scripts Which Disable / Remove Windows 10 Features and Apps
Other
6.02k stars 853 forks source link

cannot run remove onedrive "cannot remove item" "access to path denied" #222

Open vm666 opened 4 years ago

vm666 commented 4 years ago

I followed all of the steps correctly and am using admin powershell, yet i get this set of errors everytime.

Remove-Item : Cannot remove item C:\WINDOWS\WinSxS\wow64_microsoft-windows-onedrive-setup_31bf3856ad364e35_10.0.18362.1
_none_01f25b79d7a97c4b\OneDriveSetup.exe: Access to the path 'OneDriveSetup.exe' is denied.
At C:\Users\SU\Downloads\Debloat-Windows-10-master\Debloat-Windows-10-master\scripts\remove-onedrive.ps1:61 char:5
+     Remove-Item -Recurse -Force $item.FullName
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (OneDriveSetup.exe:FileInfo) [Remove-Item], UnauthorizedAccessExceptio
   n
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
Remove-Item : Cannot remove item
C:\WINDOWS\WinSxS\wow64_microsoft-windows-onedrive-setup_31bf3856ad364e35_10.0.18362.1_none_01f25b79d7a97c4b: The
directory is not empty.
At C:\Users\SU\Downloads\Debloat-Windows-10-master\Debloat-Windows-10-master\scripts\remove-onedrive.ps1:61 char:5
+     Remove-Item -Recurse -Force $item.FullName
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\WINDOWS\WinS...1f25b79d7a97c4b:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
W4RH4WK commented 4 years ago

Sorry for the late reply. At this point it's pretty normal to get some errors. These scripts operate in a best-effort manner and may fail at some points.

Let me you know if you come up with a fix. Otherwise I'd say this error is safe to ignore.

cbaldan commented 4 years ago

I faced this same issue, it's a timming thing. When the uninstall script is just finished running, some of those files are still being used by Windows itself, probably finishing up some cleanup in the backend.

What I did was break the OneDrive script in 2 parts: The first one does the uninstall and takes ownership of the files. Then I run remove-default-apps.ps1 And the deletion is postponed to after the default apps are uninstalled, which gives time for the OneDrive to finish for good.

I tested using W10 1909 in a VM and it now works 100% of the time. BTW @W4RH4WK I did one more fork of this project, but I actually did quite some work with it.

You might like some of the ideas: https://github.com/cbaldan/Debloat-Windows-10

cbaldan commented 4 years ago

I solved one more piece of the puzzle.

To successfully delete the leftovers, it's necessary to stop explorer.exe before deleting them. Plus, for whatever reason, the $env:LOCALAPPDATA\Microsoft\OneDrive was not there a few times, so I added a test before deleting.

Stop-Process -name explorer
Start-Sleep -s 3

# Removing OneDrive leftovers
foreach ($directory in (Get-ChildItem "$env:WinDir\WinSxS\*onedrive*")) {
    Remove-Item -Recurse -Force $directory.FullName
}

$localUserOneDriveFolder = "$env:LOCALAPPDATA\Microsoft\OneDrive"
if (Test-Path $localUserOneDriveFolder) {
    Remove-Item -Recurse -Force  $localUserOneDriveFolder
}
Daynicgg commented 3 years ago

Man si te fijas cuando da error te pone la ruta de el archivo el cual no se elimino solo ingresa a esa ruta y eliminalo manualmente es lo que hice y si no lo puedes eliminar descarga el IObit Unlocker te lo eliminara sin problemas espero haber ayudado

W4RH4WK commented 3 years ago

@Daynicgg Please stick to English. If that is not possible, please attach a Google Translated version of your messages.

BrunoPuccio commented 3 years ago

Man si te fijas cuando da error te pone la ruta de el archivo el cual no se elimino solo ingresa a esa ruta y eliminalo manualmente es lo que hice y si no lo puedes eliminar descarga el IObit Unlocker te lo eliminara sin problemas espero haber ayudado

he says that when the error appears, the location of the file is shown so simply go to that folder and delete it manually. If that doesn't work then try with " IObit Unlocker"

vm666 commented 3 years ago

Nice! Can you help me out with one other issue while I got you here? How do I renable microphone access after disabling with sharp app? I don't have the command here nor the logs, but I tried deleting the added registry entry and leaving the value as default, yet I am still unable to tenable the microphone. Any advice would be appreciated!

Again, thanks for your help!

On Fri, Jan 31, 2020, 12:58 AM Cleber Baldan Junior < notifications@github.com> wrote:

I solved one more piece of the puzzle.

To successfully delete the leftovers, it's necessary to stop explorer.exe before deleting them. Plus, for whatever reason, the $env:LOCALAPPDATA\Microsoft\OneDrive was not there a few times, so I added a test before deleting.

Stop-Process -name explorer Start-Sleep -s 3

Removing OneDrive leftovers

foreach ($directory in (Get-ChildItem "$env:WinDir\WinSxS*onedrive*")) { Remove-Item -Recurse -Force $directory.FullName }

$localUserOneDriveFolder = "$env:LOCALAPPDATA\Microsoft\OneDrive" if (Test-Path $localUserOneDriveFolder) { Remove-Item -Recurse -Force $localUserOneDriveFolder }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/W4RH4WK/Debloat-Windows-10/issues/222?email_source=notifications&email_token=ANXKHWKEJW7EKZDGYEQDSYDRAPR47A5CNFSM4J4VQWPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKN7D5A#issuecomment-580645364, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANXKHWOT342RX7EQZ7MBFHDRAPR47ANCNFSM4J4VQWPA .