{"id":37,"date":"2017-05-05T09:37:54","date_gmt":"2017-05-05T14:37:54","guid":{"rendered":"https:\/\/spsroot.com\/wp\/?p=37"},"modified":"2017-12-07T10:31:29","modified_gmt":"2017-12-07T16:31:29","slug":"disabling-onedrive-the-nice-way","status":"publish","type":"post","link":"https:\/\/spsroot.com\/wp\/2017\/05\/disabling-onedrive-the-nice-way\/","title":{"rendered":"Disabling OneDrive the nice way"},"content":{"rendered":"<p>A part of my PowerShell script for customizing my Windows 10 images is to uninstall OneDrive. There weren&#8217;t any problems at first until more of our staff started using Office 365. They&#8217;d go in to their OneDrive and click &#8220;Get the OneDrive apps&#8221; which would redirect to a page that says they already had it installed.<\/p>\n<p><a href=\"https:\/\/spsroot.com\/wp\/wp-content\/uploads\/2017\/05\/OneDriveStart.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-38\" src=\"https:\/\/spsroot.com\/wp\/wp-content\/uploads\/2017\/05\/OneDriveStart-300x295.png\" alt=\"Start OneDrive\" width=\"300\" height=\"295\" srcset=\"https:\/\/spsroot.com\/wp\/wp-content\/uploads\/2017\/05\/OneDriveStart-300x295.png 300w, https:\/\/spsroot.com\/wp\/wp-content\/uploads\/2017\/05\/OneDriveStart.png 496w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><!--more--><\/p>\n<p>This is supposed to use the <strong>odopen<\/strong> association to launch your running OneDrive client. If you just uninstall OneDrive from the computer, the &#8220;Start OneDrive&#8221; button would not open anything. In my script, when I uninstall OneDrive, I also modify odopen to launch the OneDriveSetup if anyone is trying to launch from\u00a0the OneDrive website.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Get-Process -Name OneDrive -ErrorAction SilentlyContinue | Stop-Process -Force\r\nIf (Test-Path \"$env:WinDir\\SysWOW64\\OneDriveSetup.exe\") {\r\n\t$run = Start-Process -FilePath \"$env:WinDir\\SysWOW64\\OneDriveSetup.exe\" -ArgumentList \"\/uninstall\" -Wait -PassThru\r\n\tREG ADD \"HKCR\\odopen\\shell\\open\\command\" \/ve \/t REG_SZ \/d \"$env:WinDir\\SysWOW64\\OneDriveSetup.exe\" \/f\r\n} ElseIf (Test-Path \"$env:WinDir\\System32\\OneDriveSetup.exe\") {\r\n\t$run = Start-Process -FilePath \"$env:WinDir\\System32\\OneDriveSetup.exe\" -ArgumentList \"\/uninstall\" -Wait -PassThru\r\n\tREG ADD \"HKCR\\odopen\\shell\\open\\command\" \/ve \/t REG_SZ \/d \"$env:WinDir\\System32\\OneDriveSetup.exe\" \/f\r\n}\r\nREG ADD \"HKCR\\odopen\" \/ve \/t REG_SZ \/d \"URL: OneDrive Client Protocol\" \/f\r\nREG ADD \"HKCR\\odopen\" \/v \"URL Protocol\" \/t REG_SZ \/f<\/pre>\n<p>In another section of my script, where I modify the user profiles, I will remove any instances of OneDrive (and OneDriveSetup) at startup.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">If ($null -eq (Get-PSDrive HKU -ErrorAction SilentlyContinue)) { New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null }\r\n$LoggedOnUsers = (Get-CimInstance -Class Win32_LoggedOnUser | Select-Object Antecedent -Unique).Antecedent.Name\r\n$HiveList = \"HKLM:\\SYSTEM\\CurrentControlSet\\Control\\hivelist\"\r\n$Hives = Get-Item -Path $HiveList | Select-Object -ExpandProperty Property | Where-Object {$_ -like \"*\\REGISTRY\\USER\\S-*\" -And $_ -notlike \"*_Classes*\"}\r\n$Users = (Get-ChildItem $env:SystemDrive\\Users -Force | Where-Object {$_.PSIsContainer} | Where-Object {$_.Name -ne \"Public\"} | Where-Object {$_.Name -ne \"All Users\"}).Name\r\nForEach ($Name in $Users) {\r\n $ntuserpath = \"$env:SystemDrive\\Users\\$Name\\ntuser.dat\"\r\n If (Test-Path $ntuserpath) {\r\n   $RegPath = $null\r\n   If ($LoggedOnUsers -like \"*$Name*\") {\r\n     ForEach ($Hive in $Hives) {\r\n       $HiveValue = (Get-ItemPropertyValue -Path \"$HiveList\" -Name \"$Hive\") -Replace \"\\\\Device\\\\HarddiskVolume[0-9]*\",\"$env:SystemDrive\"\r\n       If ($HiveValue -like \"*\\$Name\\*\") { $RegPath = $Hive.ToUpper().Replace(\"\\REGISTRY\\USER\",\"HKU\"); break }\r\n     }\r\n   }\r\n   If ($null -eq $RegPath) { $RegPath = \"HKLM\\ntuser\"; REG LOAD $RegPath \"$ntuserpath\" | Out-Null }\r\n   REG ADD \"$RegPath\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run\" \/v OneDrive \/t REG_BINARY \/d 030000005282a114a818d101 \/f\r\n   REG DELETE \"$RegPath\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\" \/v OneDrive \/f\r\n   REG DELETE \"$RegPath\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\" \/v OneDriveSetup \/f\r\n   REG DELETE \"$RegPath\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\NameSpace\\{018D5C66-4533-4307-9B53-224DE2ED1FE6}\" \/f\r\n   If ($RegPath -eq \"HKLM\\ntuser\") { REG UNLOAD $RegPath | Out-Null }\r\n }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>One thing to note, though, is that when a\u00a0user relaunches OneDriveSetup, it does initiate it across the whole computer again for all other users that then log in to the computer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A part of my PowerShell script for customizing my Windows 10 images is to uninstall OneDrive. There weren&#8217;t any problems at first until more of our staff started using Office 365. They&#8217;d go in to their OneDrive and click &#8220;Get<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[11,5],"class_list":["post-37","post","type-post","status-publish","format-standard","hentry","category-windows-10","tag-onedrive","tag-windows-10"],"_links":{"self":[{"href":"https:\/\/spsroot.com\/wp\/wp-json\/wp\/v2\/posts\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spsroot.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spsroot.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spsroot.com\/wp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/spsroot.com\/wp\/wp-json\/wp\/v2\/comments?post=37"}],"version-history":[{"count":2,"href":"https:\/\/spsroot.com\/wp\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"predecessor-version":[{"id":67,"href":"https:\/\/spsroot.com\/wp\/wp-json\/wp\/v2\/posts\/37\/revisions\/67"}],"wp:attachment":[{"href":"https:\/\/spsroot.com\/wp\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spsroot.com\/wp\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spsroot.com\/wp\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}