Disassembler0 / Win10-Initial-Setup-Script

PowerShell script for automation of routine tasks done after fresh installations of Windows 10 / Server 2016 / Server 2019
MIT License
4.7k stars 1.07k forks source link

Hangs at "Uninstalling OneDrive" #303

Closed lackovic closed 4 years ago

lackovic commented 4 years ago

"Uninstalling OneDrive" hangs for a long time (waited several minutes) on Windows 10 version 1909, with release 3.8.

At first I thought it was an isolated problem with one machine but then I saw it on different machines, with Windows 10 freshly installed.

What can I provide next time I stumble into this problem to help us troubleshoot this?

Disassembler0 commented 4 years ago

That's a tough question, because there isn't any part besides the actual uninstall which would wait for something. The script kills the running OneDrive processes, checks OS bitness, launches OneDrive's own uninstall command, waits for it to finish, restarts explorer to free a few directory locks previously held by the OneDrive extension and finally deletes said directories and a few related registry keys.

Initially, I've thought your problem may stem from the processes not being killed in time, but now I've tried it even without killing them beforehand and the uninstallation passed anyway.

1) What exact OS version do you use? (Run command systeminfo and paste lines starting with "OS Name" and "OS Version")

2) What kind of account to you use? Microsoft / Local / Active Directory?

farag2 commented 4 years ago

@lackovic check this one from me. May be it will work. https://github.com/farag2/Windows-10-Setup-Script/blob/0f0aa46d95b6d447237f2ef3abe67449cb5c2643/Win%2010.ps1#L570 Are you signed in OneDrive account whrn trying to uninstall it?

lackovic commented 4 years ago

Happened again right now.

I get pass through it by pressing Ctrl+C and re-running the script.

  1. What exact OS version do you use? (Run command systeminfo and paste lines starting with "OS Name" and "OS Version")
OS Name:       Microsoft Windows 10 Pro
OS Version:    10.0.18363 N/A Build 18363
  1. What kind of account to you use? Microsoft / Local / Active Directory?

Local.

Are you signed in OneDrive account whrn trying to uninstall it?

I am not signed in.

Disassembler0 commented 4 years ago

@lackovic: Put Set-PSDebug -Trace 2 to the beginning of UninstallOneDrive function in Win10.psm1 and Set-PSDebug -Trace 0 to the end of the same function. You should end up with something like this:

Function UninstallOneDrive {
    Write-Output "Uninstalling OneDrive..."
    Set-PSDebug -Trace 2
    Stop-Process -Name "OneDrive" -Force -ErrorAction SilentlyContinue
    Start-Sleep -s 2
    $onedrive = "$env:SYSTEMROOT\SysWOW64\OneDriveSetup.exe"
    If (!(Test-Path $onedrive)) {
        $onedrive = "$env:SYSTEMROOT\System32\OneDriveSetup.exe"
    }
    Start-Process $onedrive "/uninstall" -NoNewWindow -Wait
    Start-Sleep -s 2
    Stop-Process -Name "explorer" -Force -ErrorAction SilentlyContinue
    Start-Sleep -s 2
    If ((Get-ChildItem -Path "$env:USERPROFILE\OneDrive" -ErrorAction SilentlyContinue | Measure-Object).Count -eq 0) {
        Remove-Item -Path "$env:USERPROFILE\OneDrive" -Force -Recurse -ErrorAction SilentlyContinue
    }
    Remove-Item -Path "$env:LOCALAPPDATA\Microsoft\OneDrive" -Force -Recurse -ErrorAction SilentlyContinue
    Remove-Item -Path "$env:PROGRAMDATA\Microsoft OneDrive" -Force -Recurse -ErrorAction SilentlyContinue
    Remove-Item -Path "$env:SYSTEMDRIVE\OneDriveTemp" -Force -Recurse -ErrorAction SilentlyContinue
    If (!(Test-Path "HKCR:")) {
        New-PSDrive -Name "HKCR" -PSProvider "Registry" -Root "HKEY_CLASSES_ROOT" | Out-Null
    }
    Remove-Item -Path "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" -Recurse -ErrorAction SilentlyContinue
    Remove-Item -Path "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" -Recurse -ErrorAction SilentlyContinue
    Set-PSDebug -Trace 0
}

It'll give you more verbosity on what's happening inside the function when you run it. My money is that it's going to get stuck on

DEBUG:   10+  >>>> Start-Process $onedrive "/uninstall" -NoNewWindow -Wait

in which case there has to be something specific to you setup(s) what causes some handles to be locked. Then possibly hitting Ctrl+C will interrupt only the script and keep the OneDrive uninstallation process running and the new run simply skips the part which caused the lockup. That's just a guess, not backed by any evidence.

ejvoss commented 4 years ago

Sounds silly but this happens to me if I unconsciously click the shell window and it thinks I want to select something. It blocks the output and thus the process. Try e.g. with dir /s c: