patchWebDAV.ps1 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #Requires -RunAsAdministrator
  2. # Adds for address 127.0.0.1 the 'cryptomator-vault' alias to the hosts file
  3. function Add-AliasToHost {
  4. $sysdir = [Environment]::SystemDirectory
  5. $hostsFile = "$sysdir\drivers\etc\hosts"
  6. $aliasLine = '127.0.0.1 cryptomator-vault'
  7. foreach ($line in Get-Content $hostsFile) {
  8. if ($line -eq $aliasLine){
  9. return
  10. }
  11. }
  12. Add-Content -Path $hostsFile -Encoding ascii -Value "`r`n$aliasLine"
  13. }
  14. # Sets in the registry the webclient file size limit to the maximum value
  15. function Set-WebDAVFileSizeLimit {
  16. # Set variables to indicate value and key to set
  17. $RegistryPath = 'HKLM:\SYSTEM\CurrentControlSet\Services\WebClient\Parameters'
  18. $Name = 'FileSizeLimitInBytes'
  19. $Value = '0xffffffff'
  20. # Create the key if it does not exist
  21. If (-NOT (Test-Path $RegistryPath)) {
  22. New-Item -Path $RegistryPath -Force | Out-Null
  23. }
  24. # Now set the value
  25. New-ItemProperty -Path $RegistryPath -Name $Name -Value $Value -PropertyType DWORD -Force | Out-Null
  26. }
  27. # Changes the network provider order such that the builtin Windows webclient is always first
  28. function Edit-ProviderOrder {
  29. $RegistryPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder'
  30. $Name = 'ProviderOrder'
  31. $WebClientString = 'webclient'
  32. $CurrentOrder = (Get-ItemProperty $RegistryPath $Name).$Name
  33. $OrderWithoutWebclientArray = $CurrentOrder -split ',' | Where-Object {$_ -ne $WebClientString}
  34. $WebClientArray = @($WebClientString)
  35. $UpdatedOrder = ($WebClientArray + $OrderWithoutWebclientArray) -join ","
  36. New-ItemProperty -Path $RegistryPath -Name $Name -Value $UpdatedOrder -PropertyType String -Force | Out-Null
  37. }
  38. Add-AliasToHost
  39. Write-Output 'Ensured alias exists in hosts file'
  40. Set-WebDAVFileSizeLimit
  41. Write-Output 'Set WebDAV file size limit'
  42. Edit-ProviderOrder
  43. Write-Output 'Ensured correct provider order'
  44. exit 0