alexkirsz / alexkirsz/dispatch

This may be a feature or a tips: Instantly refresh Windows proxy settings

未关闭
#4 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
599
派生
47
PR 合并指标
30 天内没有已合并 PR

描述

After changing the proxy settings, whether it's enabling, disabling, or changing the address/port, it does not automatically applies to the whole system.

This PowerShell script from stackoverflow helps it a lot.
https://stackoverflow.com/a/39079005/6458107https://stackoverflow.com/questions/21568502/ie-enable-disable-proxy-settings-via-registry

```
function Refresh-System
{
$signature = @'
[DllImport("wininet.dll", SetLastError = true, CharSet=CharSet.Auto)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
'@

$INTERNET_OPTION_SETTINGS_CHANGED = 39
$INTERNET_OPTION_REFRESH = 37
$type = Add-Type -MemberDefinition $signature -Name wininet -Namespace pinvoke -PassThru
$a = $type::InternetSetOption(0, $INTERNET_OPTION_SETTINGS_CHANGED, 0, 0)
$b = $type::InternetSetOption(0, $INTERNET_OPTION_REFRESH, 0, 0)
return $a -and $b
}
Refresh-System
```
Save that script into something like `RefreshPROXY.ps1` and run it whenever you need to.



I usually turn this script into one line that you could run on command prompt, windows terminal, or inside a batch script however you want to.

`
powershell -command "$signature = '[DllImport("^""wininet.dll"^"", SetLastError = true, CharSet=CharSet.Auto)] public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);'; $type = Add-Type -MemberDefinition $signature -Name wininet -Namespace pinvoke -PassThru; $type::InternetSetOption(0,39,0,0); $type::InternetSetOption(0,37,0,0);" > nul
`


This could be a feature and be run as `dispatch proxy-refresh` if it were implemented. With it's own Rust code, of course, good luck devs... 👍

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。