File tree Expand file tree Collapse file tree
helpful_tools/Install-DockerCE Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -136,13 +136,16 @@ Remove-DockerService()
136136 # Stop the service first
137137 Stop-Docker
138138
139- # Remove the service
140- $service = Get-WmiObject - Class Win32_Service - Filter " Name=' $global :DockerServiceName ' "
141- if ($service )
139+ # Remove the service using sc.exe for more reliable deletion
140+ $result = & sc.exe delete $global :DockerServiceName 2>&1
141+ if ($LASTEXITCODE -eq 0 )
142142 {
143- $service.delete ()
144143 Write-Output " Docker service removed successfully."
145144 }
145+ else
146+ {
147+ Write-Warning " Failed to remove Docker service. Exit code: $LASTEXITCODE . Output: $result "
148+ }
146149 }
147150 catch
148151 {
@@ -268,12 +271,22 @@ Remove-DockerData()
268271 Write-Output " Removing Docker data directory..."
269272 try
270273 {
274+ # Take ownership of the Docker data directory and its contents
275+ # This is needed for directories like windowsfilter which have restrictive ACLs
276+ Write-Output " Taking ownership of Docker data directory..."
277+ & takeown.exe / f $global :DockerDataPath / r / d y 2> $null | Out-Null
278+
279+ # Grant full control to the current user
280+ & icacls.exe $global :DockerDataPath / grant " $env: USERNAME `:F" / t / c 2> $null | Out-Null
281+
282+ # Now attempt to remove the directory
271283 Remove-Item $global :DockerDataPath - Recurse - Force
272284 Write-Output " Docker data directory removed."
273285 }
274286 catch
275287 {
276288 Write-Warning " Failed to remove Docker data directory: $_ "
289+ Write-Warning " You may need to manually remove $global :DockerDataPath "
277290 }
278291 }
279292 else
You can’t perform that action at this time.
0 commit comments