管理人Kのひとりごと

デジモノレビューやプログラミングや写真など

JScriptでIEのProxyURLの設定を自動化する

IEをProxy環境で使うことって結構ありますよね。Windows標準機能でIEのProxyURL設定を自動化してみました。

JScriptのコード

IEを起動して、あとはショートカットキーを順次押していくだけというものです。

({
    WAIT_LONG:5000,
    WAIT_SHORT:2000,
    PROXY_URL:"http://localhost/",
    main: function () {
        var shell = WScript.CreateObject("WScript.Shell");
        
        shell.Run("iexplore.exe",1,true);
        WScript.Sleep(this.WAIT_LONG);
        
        shell.SendKeys("%t");
        WScript.Sleep(this.WAIT_SHORT);
        
        shell.SendKeys("o");
        WScript.Sleep(this.WAIT_SHORT);
        
        shell.SendKeys("^{TAB}^{TAB}^{TAB}^{TAB}");
        WScript.Sleep(this.WAIT_SHORT);
        
        shell.SendKeys("%l");
        WScript.Sleep(this.WAIT_SHORT);
        
        shell.SendKeys("%a");
        WScript.Sleep(this.WAIT_SHORT);
        
        shell.SendKeys("%s");
        WScript.Sleep(this.WAIT_SHORT);
        
        shell.SendKeys("%r");
        WScript.Sleep(this.WAIT_SHORT);
        
        shell.SendKeys(this.PROXY_URL);
    }
}).main()

拡張子「.js」と名前を付けて保存、ダブルクリックで実行すればOKです。Proxyのダイアログが表示された状態で止まります。
スペックによっては待ち時間をもう少し長くしないと空振りしてしまうことがあるかもです...