OneDrive.bat out of date?

Page 1 of 5 123 ... LastLast

  1. Posts : 194
    Windows 10
       #1

    OneDrive.bat out of date?


    Can someone look at my .bat code? and tell me if it's out of date and if there is a better guide online? The reason why I ask is when I run the .bat, it does indeed remove it, it confirms it, but in the cmd prompt, it does say there were 2-3 errors. I was wondering if there was something out there more up to date with this current build of Windows 10 Pro? I haven't updated it since Windows 10 was released.

    @echo off
    cls

    set x86="%SYSTEMROOT%\System32\OneDriveSetup.exe"
    set x64="%SYSTEMROOT%\SysWOW64\OneDriveSetup.exe"

    echo Closing OneDrive process.
    echo.
    taskkill /f /im OneDrive.exe > NUL 2>&1
    ping 127.0.0.1 -n 5 > NUL 2>&1

    echo Uninstalling OneDrive.
    echo.
    if exist %x64% (
    %x64% /uninstall
    ) else (
    %x86% /uninstall
    )
    ping 127.0.0.1 -n 5 > NUL 2>&1

    echo Removing OneDrive leftovers.
    echo.
    rd "%USERPROFILE%\OneDrive" /Q /S > NUL 2>&1
    rd "C:\OneDriveTemp" /Q /S > NUL 2>&1
    rd "%LOCALAPPDATA%\Microsoft\OneDrive" /Q /S > NUL 2>&1
    rd "%PROGRAMDATA%\Microsoft OneDrive" /Q /S > NUL 2>&1

    echo Removeing OneDrive from the Explorer Side Panel.
    echo.
    REG DELETE "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f > NUL 2>&1
    REG DELETE "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f > NUL 2>&1

    pause
    Thank you!
      My Computer


  2. Posts : 5,478
    2004
       #2

    As far as I know OneDrive uses the OneDriveSetup.exe in %localappdata% not in %SYSTEMROOT%

    You could try this to uninstall it : Uninstall OneDrive in Windows 10
      My Computer


  3. Posts : 194
    Windows 10
    Thread Starter
       #3

    Are you talking about these two lines?

    set x86="%SYSTEMROOT%\System32\OneDriveSetup.exe"
    set x64="%SYSTEMROOT%\SysWOW64\OneDriveSetup.exe"
    So would it be a problem to simply add the following?
    set x86="%localappdata%\System32\OneDriveSetup.exe"
    set x64="%localappdata%\SysWOW64\OneDriveSetup.exe"
    So that it reads:

    set x86="%SYSTEMROOT%\System32\OneDriveSetup.exe"
    set x64="%SYSTEMROOT%\SysWOW64\OneDriveSetup.exe"
    set x86="%localappdata%\System32\OneDriveSetup.exe"
    set x64="%localappdata%\SysWOW64\OneDriveSetup.exe"
      My Computer


  4. Posts : 7,606
    Windows 10 Home 20H2
       #4

    Why do you want to uninstall OneDrive via script rather than Apps & features? For fun?
      My Computer


  5. Posts : 68
    MS Win10 + Remnux Linux OS Dual Boot
       #5

    use this small utility for permanent one drive removal:
    Remove-OneDrive.exe - Mirrored.to - Mirrorcreator - Upload files to multiple hosts

    will work for new created accounts too in win10 & there will not be any one drive software preinstalled after using this utility.
      My Computer


  6. Posts : 7,606
    Windows 10 Home 20H2
       #6

    I permanently removed OneDrive via Apps & features as soon as I clean-installed Windows 10.
      My Computer


  7. Posts : 5,451
    Windows 11 Home
       #7

    SightUp said:
    Can someone look at my .bat code?

    I used it on 1909 and it worked. But I also uninstall all store apps and it might be installed as an app too.
    Disk2019 said:
    use this small utility for permanent one drive removal:
    Who made it? It is not a good idea to run a random exe from the internet, even if it does, what it claims to.

    VirusTotal
      My Computer


  8. Posts : 456
    Windows 10
       #8

    It looks to be inverted %x86% is the 64 bit version and %x64% is the 32bit version.

    If it finds 32 bit version it doesn't seem to delete the 64 bit version.
      My Computer


  9. Posts : 68
    MS Win10 + Remnux Linux OS Dual Boot
       #9

    TairikuOkami said:
    I used it on 1909 and it worked. But I also uninstall all store apps and it might be installed as an app too.

    Who made it? It is not a good idea to run a random exe from the internet, even if it does, what it claims to.

    VirusTotal
    Just a false positive response from AV engine scanning signatures. nothing else . its compiled by myself . you can see copyright on prop of this exe as my username resides there.

    - - - Updated - - -

    Powershell Script used to Compile this Executable is as follows :

    Code:
    Function Remove-OneDrive
    {
        <#
        .SYNOPSIS
            Perform a full removal of all instances of Microsoft OneDrive.
    
        .DESCRIPTION
            Performs a full removal of all instances of Microsoft OneDrive from all current user accounts.
            Loads all users' NTUSER.DAT registry hives and removes the Microsoft OneDrive auto-run hook.
            Prevents the setup and installation of Microsoft OneDrive on future user accounts.
            Removes leftover Microsoft OneDrive directories, namespace icons and environmental variables.
            Disables Microsoft OneDrive policies.
            Optionally will remove all Microsoft OneDrive Component Store files.
    
        .PARAMETER RemoveComponents
            Removes the Microsoft OneDrive files in the Component Store.
    
        .EXAMPLE
            PS C:\> Remove-OneDrive
    
        .EXAMPLE
            PS C:\> Remove-OneDrive -RemoveComponents
    
        .NOTES
            Removing the Microsoft OneDrive Component Store files does not cause any system issues but will cause Dism to report repairable image corruption when ScanHealth is run.
        #>
    
        [CmdletBinding()]
        Param
        (
            [Switch]$RemoveComponents
        )
    
        Begin
        {
            $DefaultErrorActionPreference = $ErrorActionPreference
            $ErrorActionPreference = 'SilentlyContinue'
            $ProgressPreference = 'SilentlyContinue'
        }
        Process
        {
            Clear-Host
            Write-Host "Performing a full removal of Microsoft OneDrive." -ForegroundColor Cyan
    
            # Stop any running OneDrive processes and services and uninstall the OneDrive application.
            Get-Process -Name OneDrive* | Stop-Process -Force
            Get-Service -Name OneSyncSvc* | Stop-Service -Force -NoWait
            $OneDrive = "$Env:SystemRoot\SysWOW64\OneDriveSetup.exe"
            If (!(Test-Path -Path $OneDrive)) { $OneDrive = "$Env:SystemRoot\System32\OneDriveSetup.exe" }
            Start-Process -FilePath $OneDrive -ArgumentList ('/Uninstall') -Wait
    
            # Unregister any OneDrive scheduled tasks.
            Get-ScheduledTask -TaskName *OneDrive* | Unregister-ScheduledTask -Confirm:$false
    
            # Loop through the Default User and all Current User registry hives and remove the OneDrive auto-run hook.
            $LoggedOnUsers = (Get-CimInstance -ClassName Win32_LoggedOnUser | Select-Object -Property Antecedent -Unique).Antecedent.Name
            $HiveList = "HKLM:\SYSTEM\CurrentControlSet\Control\HiveList"
            $Hives = Get-Item -Path $HiveList | Select-Object -ExpandProperty Property | Where-Object { $PSItem -like "\REGISTRY\USER\S-*" -and $PSItem -notlike "*_Classes*" }
            $Users = Get-ChildItem -Path $Env:SystemDrive\Users -Force | Where-Object { $PSItem.PSIsContainer -and $PSItem.Name -ne 'Public' -and $PSItem.Name -ne 'All Users' } | Select-Object -ExpandProperty Name
            If ((Get-PSDrive -PSProvider Registry).Name -notcontains 'HKU') { $PSDrive = New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_LOCAL_MACHINE -Scope Script }
            Push-Location -Path HKU:
            ForEach ($User In $Users)
            {
                $NTUSER = "$Env:SystemDrive\Users\$User\NTUSER.DAT"
                If (Test-Path -Path $NTUSER)
                {
                    $NTUSERHive = $null
                    If ($LoggedOnUsers -like "*$User*")
                    {
                        ForEach ($Hive In $Hives)
                        {
                            $HiveValue = (Get-ItemPropertyValue -Path $HiveList -Name $Hive) -replace "\\Device\\HarddiskVolume[0-9]*", $Env:SystemDrive
                            If ($HiveValue -like "*\$User\*") { $NTUSERHive = $Hive.ToUpper().Replace('\REGISTRY\USER', 'HKU:'); Break }
                        }
                    }
                    If (!$NTUSERHive)
                    {
                        $NTUSERHive = 'HKLM\NTUSER'
                        Start-Process -FilePath REG -ArgumentList ('LOAD "{0}" "{1}"' -f $NTUSERHive, $NTUSER) -WindowStyle Hidden -Wait
                        $NTUSERHive = $NTUSERHive.Insert(4, ':')
                        Push-Location -Path HKLM:
                    }
                    Remove-ItemProperty -LiteralPath (Join-Path -Path $NTUSERHive -ChildPath 'Software\Microsoft\Windows\CurrentVersion\Run') -Name OneDriveSetup -Force
                    Remove-ItemProperty -LiteralPath (Join-Path -Path $NTUSERHive -ChildPath 'Software\Microsoft\Windows\CurrentVersion\Run') -Name OneDrive -Force
                    New-Item -Path (Join-Path -Path $NTUSERHive -ChildPath 'Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run') -ItemType Directory -Force | New-ItemProperty -Name OneDrive -Value ([Byte[]](0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)) -PropertyType Binary -Force | Out-Null
                    If ($NTUSERHive -eq 'HKLM:\NTUSER')
                    {
                        $NTUSERHive = $NTUSERHive.Remove(4, 1)
                        Start-Process -FilePath REG -ArgumentList ('UNLOAD "{0}"' -f $NTUSERHive) -WindowStyle Hidden -Wait
                        Pop-Location
                    }
                }
            }
            Pop-Location
            If ($PSDrive) { Remove-PSDrive -Name $PSDrive.Name }
    
            # Remove the OneDrive folder namespace from the Navigation Pane.
            If ((Get-PSDrive -PSProvider Registry).Name -notcontains 'HKCR') { $PSDrive = New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT -Scope Script }
            @("HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}", "HKCR:\WOW6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}") | Remove-Item -Recurse -Force
            New-Item -Path @("HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}", "HKCR:\WOW6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}") -ItemType Directory -Force | New-ItemProperty -Name System.IsPinnedToNameSpaceTree -Value 0 -PropertyType DWord -Force | Out-Null
            If ($PSDrive) { Remove-PSDrive -Name $PSDrive.Name }
    
            # Remove the OneDrive desktop icon namespace.
            Remove-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" -Recurse -Force
    
            # Disable OneDrive policies.
            New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -ItemType Directory -Force | Out-Null
            New-Item -Path "HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\OneDrive" -ItemType Directory -Force | Out-Null
            New-Item -Path "HKCU:\Software\Microsoft\OneDrive" -ItemType Directory -Force | Out-Null
            New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name PreventNetworkTrafficPreUserSignIn -Value 1 -PropertyType DWord -Force | Out-Null
            New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name DisableFileSyncNGSC -Value 1 -PropertyType DWord -Force | Out-Null
            New-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\OneDrive" -Name DisableFileSyncNGSC -Value 1 -PropertyType DWord -Force | Out-Null
            New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name DisableFileSync -Value 1 -PropertyType DWord -Force | Out-Null
            New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name DisableMeteredNetworkFileSync -Value 1 -PropertyType DWord -Force | Out-Null
            New-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\OneDrive" -Name DisableMeteredNetworkFileSync -Value 1 -PropertyType DWord -Force | Out-Null
            New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name DisableLibrariesDefaultSaveToOneDrive -Value 1 -PropertyType DWord -Force | Out-Null
            New-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Windows\OneDrive" -Name DisableLibrariesDefaultSaveToOneDrive -Value 1 -PropertyType DWord -Force | Out-Null
            New-ItemProperty -Path "HKCU:\Software\Microsoft\OneDrive" -Name DisablePersonalSync -Value 1 -PropertyType DWord -Force | Out-Null
    
            # Disable the AutoRestartShell to prevent the explorer process from automatically restarting. Allowing us to remove any locked OneDrive files.
            Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -Value 0 -Type DWord -Force
            Stop-Process -Name explorer -Force
    
            # Remove OneDrive directories, Start Menu shell link and global environmental variable.
            Remove-Item -Path "$Env:LOCALAPPDATA\Microsoft\OneDrive" -Recurse -Force
            Remove-Item -Path "$Env:PROGRAMDATA\Microsoft OneDrive" -Recurse -Force
            Remove-Item -Path "$Env:SYSTEMDRIVE\OneDriveTemp" -Recurse -Force
            If ((Get-ChildItem -Path "$Env:USERPROFILE\OneDrive" -Recurse -Force | Measure-Object).Count -eq 0) { Remove-Item -Path "$Env:USERPROFILE\OneDrive" -Recurse -Force }
            Remove-Item -Path "$Env:AppData\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -Force
            Remove-Item -Path Env:\OneDrive -Force
    
            # Restore the AutoRestartShell back to its default value.
            Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -Value 1 -Type DWord -Force
            Start-Process -FilePath explorer
    
            # Remove the OneDrive Component Store files.
            If ($RemoveComponents.IsPresent)
            {
                Get-ChildItem -Path $Env:SystemRoot\WinSxS -Filter *OneDrive* -Force | ForEach-Object -Process {
                    Start-Process -FilePath TAKEOWN -ArgumentList ('/F "{0}" /A /R /D Y' -f $PSItem.FullName) -WindowStyle Hidden -Wait
                    Start-Process -FilePath ICACLS -ArgumentList ('"{0}" /GRANT *S-1-5-32-544:F /T /C' -f $PSItem.FullName) -WindowStyle Hidden -Wait
                    Remove-Item -Path $PSItem.FullName -Recurse -Force
                }
            }
        }
        End
        {
            $ErrorActionPreference = $DefaultErrorActionPreference
        }
    }
    
    If (([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Remove-OneDrive }
    Else { Write-Warning "Elevation is required to remove Microsoft OneDrive. Please relaunch this script as an administrator."; Start-Sleep 3; Exit }
    Last edited by Brink; 03 Feb 2020 at 11:32. Reason: code box
      My Computer


  10. Posts : 194
    Windows 10
    Thread Starter
       #10

    So, your .exe, a few questions.

    1) Does it do everything that mine does? Is anything left out?
    2) Does OneDrive need to be stopped or can I just run it and it will make it auto stop?
    3) Does it remove all traces of it?
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 02:53.
Find Us




Windows 10 Forums