【问题标题】:PowerShell script to tick proxy settings : "Use automatic configuration script" AND "Automatically detect settings"用于勾选代理设置的 PowerShell 脚本:“使用自动配置脚本”和“自动检测设置”
【发布时间】:2020-03-12 11:11:45
【问题描述】:

我想创建一个 Powershell 脚本来自动勾选代理设置“自动检测设置”和“使用自动配置脚本”为: Proxy Settings

所以我找到了一些提示,我可以用我的代理地址勾选“使用自动配置脚本”:

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

我可以勾选“自动检测设置”

$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

但如果我尝试 both 喜欢将两个代码放在同一个脚本上,它不起作用,并且只勾选“使用自动配置脚本”。

我还看到我可以使用来自 Source 的值 0d

但是当我尝试输出是 “错误:输入字符串的格式不正确。”

您对我如何做到这一点有任何想法吗? 谢谢。

【问题讨论】:

  • 试试[byte[]]$data = (Get-ItemProperty -Path $key -Name DefaultConnectionSettings).DefaultConnectionSettingsSet-ItemProperty -Path $key -Name DefaultConnectionSettings -Value $data -PropertyType Binary
  • 所以我尝试了将 0d 作为 $data[8] 的值的行,但我仍然收到相同的错误:错误:“输入字符串的格式不正确。 "还有其他想法吗?谢谢
  • 那么如何准确设置byte[8]的值呢?我认为您显示的错误是指该部分。使用$data[8] = 0x0d$data[8] = 13
  • 嗨 Theo,感谢 $data[8] = 0x0d 对我有用

标签: powershell proxy


【解决方案1】:
[byte[]]$data = (Get-ItemProperty -Path $key -Name DefaultConnectionSettings).DefaultConnectionSettings

改成

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

总的来说,这太棒了,Theo 做得很好,谢谢你的分享。

托德

【讨论】:

    猜你喜欢
    • 2011-08-14
    • 1970-01-01
    • 2018-02-16
    • 2017-08-13
    • 2010-09-06
    • 1970-01-01
    • 2015-09-17
    • 2017-03-21
    • 1970-01-01
    相关资源
    最近更新 更多