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