1

I want to create a Powershell script to automatically tick the proxy settings "Automatically detect settings" and "Use automatic configuration script" as : Proxy Settings

So I found some tips, I am able to tick "Use automatic configuration script" with my proxy address with :

set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name AutoConfigURL -value 'proxy address'

And I am able to tick "Automatically detect settings" with

$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections'
$data = (Get-ItemProperty -Path $key -Name DefaultConnectionSettings).DefaultConnectionSettings
$data[8] = 9
Set-ItemProperty -Path $key -Name DefaultConnectionSettings -Value $data

But If I try both like to put the two codes on the same script it doesn't work and only "Use automatic configuration script" is ticked.

I also saw that I can use the value 0d from : Source.

But when I tried that the output is "Error: Input string was not in a correct format."

Do you have any Idea on how I can do this ? Thank you.

Tommy Rivers
  • 11
  • 1
  • 4
  • Try `[byte[]]$data = (Get-ItemProperty -Path $key -Name DefaultConnectionSettings).DefaultConnectionSettings` and `Set-ItemProperty -Path $key -Name DefaultConnectionSettings -Value $data -PropertyType Binary` – Theo Mar 12 '20 at 12:32
  • So i tried your lines putting **0d** as value for $data[8] But I still get the same error : Error: "Input string was not in a correct format." Any other Ideas ? thanks – Tommy Rivers Mar 13 '20 at 11:35
  • Then how do you set the value of byte[8] exactly? I think the error you show refers to that part. Use `$data[8] = 0x0d` or `$data[8] = 13` – Theo Mar 13 '20 at 11:43
  • Hi Theo, Thanks for that it worked for me with `$data[8] = 0x0d` – Tommy Rivers Mar 18 '20 at 15:59

1 Answers1

2
[byte[]]$data = (Get-ItemProperty -Path $key -Name DefaultConnectionSettings).DefaultConnectionSettings

change to

[byte[]]$data = (Get-ItemProperty -Path $key).DefaultConnectionSettings

Overall, this is wonderful, great job Theo, thank you for sharing.

Todd

tdsan
  • 21
  • 3