编码配置方法

编码配置方法

我们正在尝试为 Azure 部署 ARM 模板。我们想为所有用户和系统帐户设置代理。但我们无法做到这一点。当我们使用此 powershell 脚本时,当前用户有代理,但没有系统帐户。有什么建议吗?

<#
.Synopsis
This function will set the proxy settings provided as input to the cmdlet.
.Description
This function will set the proxy server and (optinal) Automatic configuration script.
.Parameter ProxyServer
This parameter is set as the proxy for the system.
Data from. This parameter is Mandatory
.Example
Setting proxy information
Set-InternetProxy -proxy "proxy:7890"
.Example
Setting proxy information and (optinal) Automatic Configuration Script 
Set-InternetProxy -proxy "proxy:7890" -acs "http://proxy:7892"
#>

#[CmdletBinding()]
Param(        
    [Parameter(Mandatory=$True,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
    [String[]]$Proxy,

    [Parameter(Mandatory=$False,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
    [AllowEmptyString()]
    [String[]]$acs      
)

Begin
{
    $regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"        
}    
Process
{        
    Set-ItemProperty -path $regKey ProxyEnable -value 1
    Set-ItemProperty -path $regKey ProxyServer -value $proxy

    if($acs) 
    {            
        Set-ItemProperty -path $regKey AutoConfigURL -Value $acs          
    }

    #$obj = Get-ItemProperty -Path Registry::”HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
    #Set-ItemProperty -Path Registry::”HKEY_USERS\S-1-5-18\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" -Name DefaultConnectionSettings -Value $obj.DefaultConnectionSettings
    #Set-ItemProperty -Path Registry::”HKEY_USERS\S-1-5-18\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" -Name SavedLegacySettings -Value $obj.SavedLegacySettings
    #$obj = Get-ItemProperty -Path Registry::”HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
    #Set-ItemProperty -Path Registry::”HKEY_USERS\S-1-5-18\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyEnable -Value $obj.ProxyEnable
    #Set-ItemProperty -Path Registry::”HKEY_USERS\S-1-5-18\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name Proxyserver -Value $obj.Proxyserver
}     
End
{
    Write-Output "Proxy is now enabled"
    Write-Output "Proxy Server : $proxy"

    if ($acs)
    {
        Write-Output "Automatic Configuration Script : $acs"
    }
    else
    {
        Write-Output "Automatic Configuration Script : Not Defined"
    }
}

答案1

根据上面的脚本,您已经找到了所需的密钥。

您设置了错误的密钥。请尝试以下方法:

Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings

在此键上:

HKEY_USERS\S-1-5-18

你应该会很优秀!

答案2

编码配置方法

整个配置由系统编码为二进制值,并存储在默认连接设置注册表值。

优势:

  • 您只需处理一个注册表值

退税:

  • 您必须使用现有用户帐户创建配置才能获得默认连接设置
  • 您必须对每个用户单独应用它

1.设置连接设置就像您在当前用户会话中希望的那样

2.获取匹配的值连接设置来自当前登录的用户

Get-ItemPropertyValue -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections' -Name 'DefaultConnectionSettings'

3.用之前的结果更新此代码的第一行,以在系统帐户

#This is the new connection settings you want to apply
$DefaultConnectionSettings = [byte[]](70,0,0,0,6,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,39,0,0,0,104,116,116,112,115,58,47,47,119,101,98,112,114,111,120,121,46,109,121,100,111,109,97,105,110,46,99,111,109,47,112,114,111,120,121,46,112,97,99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)

#This is the key of the LOCAL SYSTEM account
$IESettingsKey = 'Registry::HKEY_USERS\S-1-5-18\Software\Microsoft\Windows\CurrentVersion\Internet Settings'

$IEConnectionsKey = Join-Path -Path $IESettingsKey -ChildPath 'Connections'

#If the Connection subkey does not exist, create the subkey
If(-not(Test-Path -Path $IEConnectionsKey)){
    New-Item -Path $IESettingsKey -Name 'Connections'
}

try{
    #If the DefaultConnectionSettings already exists, set it with the new value
    $Null = Get-ItemPropertyValue -Path $IEConnectionsKey -Name 'DefaultConnectionSettings'
    Set-ItemProperty -Path $IEConnectionsKey -Name 'DefaultConnectionSettings' -Value $DefaultConnectionSettings
}
catch{
    #If the DefaultConnectionSettings does not exist, create it with the new value
    New-ItemProperty -Path $IEConnectionsKey -Name 'DefaultConnectionSettings' -Value $DefaultConnectionSettings -PropertyType Binary
}

答案3

显式配置方法

该配置是几个注册表值的组合。

优势:

  • 该配置易于人类阅读。
  • 该配置可以一次应用于所有用户。

退税:

  • 没有注册表值可以启用或禁用自动检测设置环境

  • 如果您使用 PowerShell,则必须确保父注册表项存在,并检查匹配的值是否存在,然后才能设置数据。例如,当您想要设置 AutoConfig 值时,必须首先创建控制面板注册表项(如果它不存在),否则您将收到错误。

配置值:

笔记

位于下方的值
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings
也必须设置在下方
HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings

  • 使用自动配置脚本
HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet 设置\AutoConfigURL = URL

例子:http://proxy.mydomain.com/proxy.pac

  • 为你的 LAN 使用代理服务器
HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet 设置\ProxyEnable = 0|1
  • 要使用的代理地址对所有协议使用相同的代理服务器已检查
HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer = URL:端口号

例子:http://proxy.mydomain.com:80

  • 对所有协议使用相同的代理服务器未选中
HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer = URL 列表:端口号

例子:http://proxy.mydomain.com:80;https://proxy.mydomain.com:443;ftp://ftp.mydomain.com:21

  • 绕过本地地址的代理服务器什么也没有不要对以以下地址开头的地址使用代理服务器
HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet 设置\ProxyOverride = <本地>

例子:<LOCAL>

  • 绕过本地地址的代理服务器和一些东西不要对以以下地址开头的地址使用代理服务器
HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride = FQDN 列表

例子:Mydomain.com;AnotherDomain.com

应用范围:

  • 将代理配置应用于所有用户
HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet 设置\ProxySettingsPerUser = 0|1
  • 防止用户覆盖代理配置
HKLM:\Software\Policies\Microsoft\Internet Explorer\控制面板\代理 = 0|1

相关内容