autochange proxy settings

Posted on 31st August 2008 by Vasilich in Miranda IM

Today I describe my way of daily using Miranda IM:
First of all – I start MirandaIM from USB Stick – it gives me freedom to use it on every PC with Windows, without any need to synchronize my chat history. I use several languages when chatting, so I have to use Unicode MirandaIM. Moreover, I haven’t seen any PC with Windows 9x last four years, so I don’t have any reason to use ANSI version.
Starting Miranda from USB has one (at least) disadvantage – start time drastically increases. I have profile about 50 Mbytes, and it takes about 15 seconds for Miranda to start (though simple copying of profile file in Explorer takes about 4 seconds); and, though I use dbx_mmap driver, it doesn’t really help to decrease start time.
One of things that disturbing me every time when starting Miranda – need to think about internet connection. So at home I have direct connection (via DSL router, with uPnP), and at work – via corporate proxy. Unfortunately, Miranda cannot read proxy settings from IE in Windows, so I need to go to options – network, and disable/enable proxy settings for all protos. Then I decided to automate it somehow. After some experiments I got what I need: just start Miranda without need to think if it is PC at work or at home. So here is the way I achieved it:

  1. we have to start Miranda from batch file, because proxy settings are read only at Miranda start, and if we change proxy settings after all protos are started, then we have to restart Miranda anyway. In this batch file we check where we are – at work or at home. I did it checking hostname of computer. And depending on my defined location I copied appropriate *.ini file to Autoexec*.ini in Miranda folder. Here is an example of my batch file:

    if %COMPUTERNAME% == IGOR-XP goto Home
    if %COMPUTERNAME% == W-4000-012 goto Work
    echo Unknown PC. Trying to start without proxy
    pause
    goto Home

    :Work
    rem work proxy settings
    copy work.ini autoexec_proxy.ini
    start miranda32.exe
    goto End

    :Home
    rem No proxy settings
    copy home.ini autoexec_proxy.ini
    start miranda32.exe
    goto End

    :End

    I hope everything is clear here, so I explain the content of *.ini files.

  2. in my Work.ini file I enable proxy settings for all my protocols, and do some additional tweaks, like disabling all sounds, popups, disabling direct filetransfers for Jabber, set clist to show only one icon in tray, etc.

    SETTINGS:

    [Netlib]
    NLEnableUPnP=b0
    NLUseProxy=b1[ICQ]
    NLUseProxy=b1

    [ICQP2P]
    NLUseProxy=b1
    NLEnableUPnP=b0

    [ICQJ]
    NLUseProxy=b1

    [ICQJP2P]
    NLUseProxy=b1
    NLEnableUPnP=b0

    [JABBER]
    NLUseProxy=b1
    NLEnableUPnP=b0
    BsDirect=b0
    Resource=uWork
    ManualConnect=b1

    [MSN]
    NLUseProxy=b1
    UseGateway=b1
    NLEnableUPnP=b0

    [MSN_HTTPS]
    NLUseProxy=b1

    [MSN2]
    NLUseProxy=b1
    UseGateway=b1
    NLEnableUPnP=b0

    [MSN2_HTTPS]
    NLUseProxy=b1

    [IRC]
    NLUseProxy=b1
    NLEnableUPnP=b0

    [IRC DCC]
    NLUseProxy=b1
    NLEnableUPnP=b0

    [IRC_Freenode]
    NLUseProxy=b1
    NLEnableUPnP=b0

    [IRC_Freenode DCC]
    NLUseProxy=b1
    NLEnableUPnP=b0

    [IRC2]
    NLUseProxy=b1
    NLEnableUPnP=b0

    [IRC2 DCC]
    NLUseProxy=b1
    NLEnableUPnP=b0

    [MRA]
    NLUseProxy=b1
    NLEnableUPnP=b0

    [MRA Avatars]
    NLUseProxy=b1

    [Updater]
    NLUseProxy=b1

    [UpdateNotify]
    NLUseProxy=b1

    [PopUp]
    ModuleIsEnabled=b0

    [Skin]
    UseSound=b0

    [CList]
    TrayIcon=b1

    For Home.ini I do it in reverse way (here I give just small part of it because settings are very similar):

    SETTINGS:

    [Netlib]
    NLUseProxy=b0
    NLEnableUPnP=b1

    [ICQ]
    NLUseProxy=b0

    [ICQP2P]
    NLUseProxy=b0
    NLEnableUPnP=b1

    [ICQJ]
    NLUseProxy=b0

    [ICQJP2P]
    NLUseProxy=b0
    NLEnableUPnP=b1

    [JABBER]
    NLUseProxy=b0
    NLEnableUPnP=b1
    BsDirect=b1
    Resource=uHome
    ManualConnect=b0

    [MSN]
    NLUseProxy=b0
    NLEnableUPnP=b1
    UseGateway=b0

    [MSN_HTTPS]
    NLUseProxy=b0
    ……………

  3. to make all this possible we need to modify our MirandaBoot.ini file. I will describe necessary changes and comment some of them.

    [Database]
    ProfileDir=.
    ;This setting allows us to use profile file in our Miranda folder and not in windows user profile folder.

    [AutoExec]
    Use=yes
    Glob=autoexec_*.ini
    Safe=CLC Icons CLUI CList SkinSounds
    Unsafe=AIM ICQ MSN Jabber
    OverrideSecurityFilename=autoexec_proxy.ini
    ;This line gives us possibility NOT to be warned when file with given name is imported, but warning will still be given for all other autoexec_*.ini files - it is kinda security for us ;)
    Warn=onlyunsafe
    OnCompletion=recycle
    RenamePrefix=done_

  4. after all preparations we need to set proper proxy settings for every protocol in Miranda options, and that’s it.

This example (actually, these are my current settings) describes how to automatically handle presence of proxy at work and direct connect at home. If you have more than 2 PCs with different proxy settings, then you need to:

  • extend your batch file to recognize 3rd PC and copy appropriate *.ini file;
  • create 3rd *.ini file for 3rd PC
  • extend all ini files with proxy settings. Here are all relevant proxy settings for each protocol (values given just for example):

    NLUseProxy=b0
    NLProxyType=b4
    NLProxyPort=w3128
    NLUseProxyAuth=b0
    NLProxyAuthUser=s
    NLProxyAuthPassword=s
    NLUseProxyAuthNtlm=b0
    NLDnsThroughProxy=b0
    NLSpecifyOutgoingPorts=b0
    NLSpecifyIncomingPorts=b0
    NLIncomingPorts=s2000-2010
    NLProxyServer=s192.168.150.2
    NLOutgoingPorts=s2000-2010
    NLEnableUPnP=b1

Sure this thing will get complex. But you need just set it once and forget about it after – it will silently do its job and free you from routine to change all proxy settings every time.

I hope this short manual helps you to achieve easy using of Miranda on USB stick – even with different proxy setting on different PCs.

5 Comments »

  1. Thanks a lot for such interesting post :) It’s very helpfull

    Comment by SaD — 31 August 2008 @ 10:40

  2. интересное решение проблемы =)

    Comment by x1shn1k — 31 August 2008 @ 12:05

  3. А можно всё тоже самое только по русски?

    Comment by DimON — 9 September 2008 @ 11:04

  4. 2DimON. Вроде бы все описано настолько, что даже машинный перевод будет удобоварим…

    Comment by Quadra — 14 September 2008 @ 11:51

  5. Thanks Vasilich, for this long and interesting blog :)

    Comment by endstille — 2 June 2009 @ 18:40

Leave a comment

Powered by WP Hashcash