Ruby – Read/Write ProxyServer details in Windows registry

Ruby – Read/Write ProxyServer details in Windows registry

Code:

require ‘win32/registry’

def get_proxy
path = ‘Software\Microsoft\Windows\CurrentVersion\Internet Settings’
type, value =     Win32::Registry::HKEY_CURRENT_USER.open(path).read (‘ProxyServer’)
puts value
end

def set_proxy
path = ‘Software\Microsoft\Windows\CurrentVersion\Internet Settings’
name=’ProxyServer’
data=’socks=34.12.78.92:54323′
type=1

Win32::Registry::HKEY_CURRENT_USER.open (path,Win32::Registry::KEY_WRITE).write(name,type,data)
end

get_proxy
set_proxy
get_proxy

Output:

socks=68.42.78.102:56773
socks=34.12.78.92:54323

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s