Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sing-box以windows服务方式启动时,set_system_proxy字段设置为true但无法正常设置开启windows系统代理 #2001

Open
4 of 5 tasks
ericsyj opened this issue Aug 4, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@ericsyj
Copy link

ericsyj commented Aug 4, 2024

操作系统

Windows

系统版本

windows 10 64位

安装类型

sing-box 原始命令行程序

如果您使用图形客户端程序,请提供该程序版本。

No response

版本

sing-box version 1.10.0-alpha.28

Environment: go1.22.5 windows/amd64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_ech,with_utls,with_reality_server,with_acme,with_clash_api
Revision: 3c21bd7f6bfdff0f01a523ab6a5d6734e339e6af
CGO: disabled

描述

sing-box使用类似winsw的包装器以windows服务方式启动时,set_system_proxy字段设置为true但无法正常设置开启windows系统代理。查阅源码后发现,sing-box在windows平台设置系统代理使用的应该是windows api InternetSetOptionW,根据此文档的描述,该函数不能用于服务方式设置系统代理,如果要使用服务方式启动,应使用WinHTTP中的api,此问题可能是上述原因造成的。直接在CMD终端中使用命令启动sing-box则不会出现此问题。希望sing-box能够适配以提供更好的兼容性,谢谢!

重现方式

在入站中使用以下配置,并使用windows服务方式启动sing-box

"inbounds": [
    {
        "type": "mixed",
        "tag": "mixed-in",
        "listen": "127.0.0.1",
        "listen_port": 54321,
        "set_system_proxy": true
    }
 ]

日志

无任何异常日志产生

支持我们

完整性要求

  • 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
  • 我保证提供了可以在本地重现该问题的服务器、客户端配置文件与流程,而不是一个脱敏的复杂客户端配置文件。
  • 我保证提供了可用于重现我报告的错误的最简配置,而不是依赖远程服务器、TUN、图形界面客户端或者其他闭源软件。
  • 我保证提供了完整的配置文件与日志,而不是出于对自身智力的自信而仅提供了部分认为有用的部分。
@SagerNet SagerNet deleted a comment from Su-Du Aug 5, 2024
@nekohasekai
Copy link
Member

预期行为,要从服务修改系统代理,请修改服务使其从 Administrator 而不是 System 账号启动。

@nekohasekai nekohasekai added the enhancement New feature or request label Aug 5, 2024
@dyhkwong
Copy link
Contributor

dyhkwong commented Aug 5, 2024

https://learn.microsoft.com/en-us/previous-versions/troubleshoot/browsers/development-website/wininet-not-supported-in-services

The problem with running WinInet in a service is that WinInet uses settings from the registry for SSL information, proxy information, and more. Services do not load the HKEY_CURRENT_USER registry hive, so this information is not available.

如果情况确实如其所述,那么该函数实际修改的注册表项甚至都没有加载,连直接修改注册表项都是不可行的。所以这是个 won't fix。作为替代方案,请修改服务的运行用户。

如果要使用服务方式启动,应使用 WinHTTP 中的api

WinInet 的系统代理与 WinHTTP 的系统代理是两个不同的东西,大多数软件不会去设置也不会理会 WinHTTP 系统代理。且 WinHTTP 系统代理实际保存的位置在 HKEY_LOCAL_MACHINE 中,需要提升的权限。

@ericsyj
Copy link
Author

ericsyj commented Aug 6, 2024

@dyhkwong @nekohasekai 感谢两位大佬回复,实测将服务运行用户改为当前登录用户后可以正常设置系统代理。此外,由于本人使用的不是本地Administrator账户登录,经测试使用Administrator账户运行服务也无法正常设置系统代理,应该是windows的限制吧。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants