2009-05-26

VB Script to Switch Proxy Server

I need to switch proxy server frequently. For Firefox, there is a handy add-on called FoxyProxy. However, for Internet Explorer, I have resorted to write a VB script called switch_proxy.vbs and put it on a convenient point (either at Start menu or on Desktop)

After clicking it, the following selection menu will pop up:

For instance, if option 1 is selected, then the acknowledgment dialogue will display to confirm the new setting:

On the other hand, if option 0 to disable the proxy setting, the following dialogue will be shown:

The source code is pasted as follows:



Rem Change the following entries to suit you name
ProxyName1 = "Proxy Server 1"
ProxyServer1 = "proxy.server1.com"
ProxyPort1 = "8080"
ProxyName2 = "Proxy Server 2"
ProxyServer2 = "proxy.server2.com"
ProxyPort2 = "8080"


Const HKEY_CURRENT_USER = &H80000001
strComputer = "."

Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings"

strValueName = "ProxyEnable"
objRegistry.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
IntProxy = strValue

strValueName = "ProxyServer"
objRegistry.GetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
StrProxy = strValue

dim usr_input
usr_input=InputBox("Current ProxyEnable = " & IntProxy & chr(13) & chr(13) & _
"Current Proxy Server = " & StrProxy & chr(13) & chr(13) & _
"Enter New Choice :" & chr(13) & chr(13) & _
"0 : Disable Proxy" & chr(13) & _
"1 : " & ProxyName1 & chr(13) & _
"2 : " & ProxyName2 , _
"Proxy Management")

if usr_input = "" then WScript.Quit

Select Case usr_input
Case "0"
strValueName = "ProxyEnable"
dwValue = 0
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue

Case "1"
strValueName = "ProxyEnable"
dwValue = 1
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue

strValueName = "ProxyServer"
strValue = ProxyServer1 & ":" & ProxyPort1
objRegistry.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue

Case "2"
strValueName = "ProxyEnable"
dwValue = 1
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue

strValueName = "ProxyServer"
strValue = ProxyServer2 & ":" & ProxyPort2
objRegistry.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
End Select

strValueName = "ProxyEnable"
objRegistry.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
IntProxy = strValue

strValueName = "ProxyServer"
objRegistry.GetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
StrProxy = strValue

MsgBox "ProxyEnable = " & IntProxy & chr(13) & chr(13) & "Proxy Server = " & StrProxy, ,"New Proxy Settings"



You can change the first few lines of sources to reflect your requirement.

2009-05-16

命定論

又是另一嚴肅的題目!

事緣近來在明珠台再看星球大戰(By the way,我不喜歡電視台跟電影上映的次序,即Episode 4,5,6,1,2,3,來播出,所以我錄影後再跟原情節time-line看Episodes 1-6),常常聽到的一句話:This is your destiny!

的確,近來觀察身邊人,他們的行為都是某程度上受到其性格和天生的優缺點影響,尤其是年紀越大便更明顯。

佛家有講的「習氣」,現代也講基因影響行為。

年少時,覺得甚麼也可改變,所謂「命運在我手」,現在年紀大了,覺得世界在變,反而要自己變是最困難的!

自從牛頓的機械宇宙論發展到量子力學,其中的Uncertainty Principle最教我迷思,我們只可以用Probability Density Function來描述宇宙,但是當中的Randomness有多random?

數學或電腦學中,我們只有pseudo random number generator。

佛家講無常。

或者,是不是人生的過程就是體驗sigma (standard deviation)趨向zero?