透過手動方法備份IE8加速器,以及利用C#所撰寫的IE8備份加速器的小程式來備份
一、前言
在之前的文章 備份IE8視覺化搜尋的小程式 提供了IE8備份視覺化搜尋的方式,而另外一個我很喜歡的功能 "加速器" ,也可以透過類似的方式做備份,以下介紹手動備份,以及透過所寫的程式碼作備份。
二、方法
想要備份IE8的加速器功能,首先要知道這些設定放在電腦的哪邊,在加速器的設定上,可分成兩個部份,一個是機碼的部份,另一個是加速器ICO圖檔與XML檔案的部份,以下分別描述這兩樣的位置與備份方式的手動備份方式
1. 加速器的機碼
IE8 加速器的的機碼放置在Windows Registry中的
[ HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Activities ]
如下圖所示,在 登錄編輯程式 中,可以透過手動匯出機碼的方式,在[ 登入編輯程式 ] 工具列上 -> [ 檔案 ] -> [ 匯出 ],匯出成 *reg 登錄檔,或者可以透過以下指令將 加速器 的機碼備份出來
 REG EXPORT "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Activities" C:\Accelerator.reg
REG EXPORT "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Activities" C:\Accelerator.reg
2. 加速器的圖示ICO與XML
如下圖所示,在機碼中的ICO與XML,放置了 加速器的 ICO 檔案與 XML 檔案所在位置,從這邊我們可以得知,其資料夾的位置在以下路徑
 C:\Documents and Settings\<User Account>\Local Settings\Application Data\Microsoft\Internet Explorer\Services
C:\Documents and Settings\<User Account>\Local Settings\Application Data\Microsoft\Internet Explorer\Services
3. 自動備份加速器的程式
透過上述的方式,備份 機碼、ICO、XML,就能將 IE8 的加速器設定做備份,而透過以上方法,用C#撰寫了一個小程式,可以備份出 IE8 視覺化設定,以下為程式碼
 using System;
using System; 02
 using System.Collections.Generic;
using System.Collections.Generic; 03
 using System.ComponentModel;
using System.ComponentModel; 04
 using System.Data;
using System.Data; 05
 using System.Drawing;
using System.Drawing; 06
 using System.Text;
using System.Text; 07
 using System.Windows.Forms;
using System.Windows.Forms; 08
 
 09
 namespace WindowsApplication16
namespace WindowsApplication16 10
 {
{ 11
 public partial class Form1 : Form
    public partial class Form1 : Form 12
 {
    { 13
 public Form1()
        public Form1() 14
 {
        { 15
 InitializeComponent();
            InitializeComponent(); 16
 }
        } 17
 
 18
 private void Form1_Load(object sender, EventArgs e)
        private void Form1_Load(object sender, EventArgs e) 19
 {
        { 20
 // 預設值
            // 預設值 21
 txtFileName.Enabled = false;
            txtFileName.Enabled = false; 22
 txtFolder.Enabled = false;
            txtFolder.Enabled = false; 23
 txtICO.Enabled = false;
            txtICO.Enabled = false; 24
 txtFileName.Text = "Accelerator.reg";   // 預設匯出後關於加速器的檔案名稱
            txtFileName.Text = "Accelerator.reg";   // 預設匯出後關於加速器的檔案名稱 25
 txtFolder.Text = "C:\\";                    // 預設匯出的路徑
            txtFolder.Text = "C:\\";                    // 預設匯出的路徑 26
 txtICO.Text = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\Internet Explorer\Services";  // 取得目前加速器ICO目錄
            txtICO.Text = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\Internet Explorer\Services";  // 取得目前加速器ICO目錄  27
 }
        } 28
 
 29
 // 使用者設定要將加速器的備份路徑
        // 使用者設定要將加速器的備份路徑 30
 private void btnFolder_Click(object sender, EventArgs e)
        private void btnFolder_Click(object sender, EventArgs e) 31
 {
        { 32
 if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) 33
 {
            { 34
 txtFolder.Text = folderBrowserDialog1.SelectedPath;
                txtFolder.Text = folderBrowserDialog1.SelectedPath; 35
 }
            } 36
 }
        } 37
 
 38
 private void btnBackup_Click(object sender, EventArgs e)
        private void btnBackup_Click(object sender, EventArgs e) 39
 {
        { 40
 if ((txtFolder.Text.Trim() == "") && (txtFileName.Text.Trim() == ""))
            if ((txtFolder.Text.Trim() == "") && (txtFileName.Text.Trim() == "")) 41
 {
            { 42
 MessageBox.Show("請輸入檔案名稱與路徑");
                MessageBox.Show("請輸入檔案名稱與路徑"); 43
 return;
                return; 44
 }
            } 45
 
 46
 string sourcePath = txtICO.Text;
            string sourcePath = txtICO.Text; 47
 string targetPath = ModifyFolderName(txtFolder.Text) + @"AcceleratorBackup\";
            string targetPath = ModifyFolderName(txtFolder.Text) + @"AcceleratorBackup\"; 48
 
 49
 if (!System.IO.Directory.Exists(targetPath))
            if (!System.IO.Directory.Exists(targetPath)) 50
 {
            { 51
 System.IO.Directory.CreateDirectory(targetPath);
                System.IO.Directory.CreateDirectory(targetPath); 52
 }
            } 53
 
 54
 // 備份加速器的ICO與XML
            // 備份加速器的ICO與XML 55
 if (System.IO.Directory.Exists(sourcePath))
            if (System.IO.Directory.Exists(sourcePath)) 56
 {
            { 57
 string[] files = System.IO.Directory.GetFiles(sourcePath);
                string[] files = System.IO.Directory.GetFiles(sourcePath); 58
 
 59
 foreach (string s in files)
                foreach (string s in files) 60
 {
                { 61
 string fileName = System.IO.Path.GetFileName(s);
                    string fileName = System.IO.Path.GetFileName(s); 62
 string fileExtension = System.IO.Path.GetExtension(s).ToLower();
                    string fileExtension = System.IO.Path.GetExtension(s).ToLower(); 63
 if (fileExtension == ".ico" || fileExtension == ".xml")
                    if (fileExtension == ".ico" || fileExtension == ".xml") 64
 {
                    { 65
 string destFile = System.IO.Path.Combine(targetPath, fileName);
                        string destFile = System.IO.Path.Combine(targetPath, fileName); 66
 System.IO.File.Copy(s, destFile, true);
                        System.IO.File.Copy(s, destFile, true); 67
 }
                    } 68
 }
                } 69
 
 70
 // 備份加速器的機碼
                // 備份加速器的機碼 71
 string FileFullName = targetPath + txtFileName.Text;
                string FileFullName = targetPath + txtFileName.Text; 72
 System.Diagnostics.Process.Start("REG", @"EXPORT ""HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Activities"" " + FileFullName);
                System.Diagnostics.Process.Start("REG", @"EXPORT ""HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Activities"" " + FileFullName); 73
 System.Threading.Thread.Sleep(3000);
                System.Threading.Thread.Sleep(3000); 74
 textBox1.Text = System.IO.File.ReadAllText(FileFullName);
                textBox1.Text = System.IO.File.ReadAllText(FileFullName); 75
 }
            } 76
 else
            else 77
 {
            { 78
 MessageBox.Show("目錄不存在!");
                MessageBox.Show("目錄不存在!"); 79
 }
            } 80
 }
        } 81
 
 82
 // 透過 FolderBrowserDialog 取得的路徑,在最後加上\,例如"C:\NewDir"變成"C:\NewDir\"
        // 透過 FolderBrowserDialog 取得的路徑,在最後加上\,例如"C:\NewDir"變成"C:\NewDir\" 83
 private string ModifyFolderName(string direction)
        private string ModifyFolderName(string direction) 84
 {
        { 85
 if (direction.Substring(direction.Length - 1, 1) != "\\")
            if (direction.Substring(direction.Length - 1, 1) != "\\") 86
 {
            { 87
 direction += "\\";
                direction += "\\"; 88
 }
            } 89
 return direction;
            return direction; 90
 }
        } 91
 }
    } 92
 }
}
三、結語
本文提供手動備份IE8加速器設定的方式,以及透過C#撰寫的程式來自動備份IE8加速器,希望能對網友有幫助。
四、參考
http://heresy.spaces.live.com/blog/cns!E0070FB8ECF9015F!6481.entry
 using
using 