Change Windows browser proxy settings via ruby scr

2019-07-29 06:11发布

I'm looking for some code/library to programmatically change proxy settings for popular browsers using Ruby on Windows. Thanks.

1条回答
Luminary・发光体
2楼-- · 2019-07-29 06:46

For Internet Explorer the settings are stored in the Registry (under HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings.) Look for ProxyServer, ProxyOverride etc. so these could be modified using Win32::Registry. e.g.

require 'win32/registry'    

proxy = "proxy goes here"
Win32::Registry::HKEY_CURRENT_USER.open(
  "Software\\Microsoft\\Windows\CurrentVersion\\Internet Settings\\",
  Win32::Registry::KEY_WRITE) do |reg|
    reg.write("ProxyServer",Win32::Registry::REG_SZ, proxy)
end 

For Firefox you would need to determine which profile you wanted to change and could then modify the prefs.js file. However if Firefox was running at the time then I don't think it wouldn pickup your your change and would rewrite the prefs file with the original value on exiting.

查看更多
登录 后发表回答