在我正在寫的應用程序,我試圖通過爲了實現這一修改preferences
文件如何保持/保護文件不被修改?
改變谷歌Chrome瀏覽器的默認主頁,我使用下面的代碼snippest
private void button1_Click(object sender, EventArgs e)
{
const int LikeWin7 = 6;
OperatingSystem osInfo = Environment.OSVersion;
DirectoryInfo strDirectory;
String path = null, file = null, data;
if (osInfo.Platform.Equals(System.PlatformID.Win32NT))
if (osInfo.Version.Major == LikeWin7)
path = Environment.GetEnvironmentVariable("LocalAppData") +
@"\Google\Chrome\User Data\Default";
if (path == null || path.Length == 0)
throw new ArgumentNullException("Fail. Bad OS.");
if (!(strDirectory = new DirectoryInfo(path)).Exists)
throw new DirectoryNotFoundException("Fail. The directory was not fund");
if (!new FileInfo(file = Directory.GetFiles(strDirectory.FullName, "Preferences*")[0]).Exists)
throw new FileNotFoundException("Fail. The file was not found.", file);
Mdata info = FindData(data = System.IO.File.ReadAllText(file));
// Console.WriteLine(info.homepage);
// Console.WriteLine(info.isNewTab);
MessageBox.Show(info.homepage);
// replace text now
String strFile = File.ReadAllText(file);
strFile = strFile.Replace(info.homepage, "www.monde-presse.com");
File.WriteAllText(file, strFile); }
當我點擊該按鈕,首次啓動Google Chrome時,默認主頁會成功更改,但在關閉並重新打開後,我注意到prefrences
文件將被修改爲與修改之前相同。對於Mozilla Firefox和Internet Explorer,每件事情都可以正常工作,但對於Google Chrome瀏覽器,它只能工作一次,在瀏覽器重新啓動後,該文件就像在修改之前一樣。
也許,有可能保持我的文件運行,並檢查每個時間間隔的任何修改,但我知道這將是資源密集型的,因此我正在尋找某種方式讓我更改默認主頁成功的方式。
如何保護我對文件的修改,避免Google Chrome再次修改文件,或者有其他方法可以永久更改默認主頁?
谷歌鉻顯然使用某種機制來防止人們在不合需要的莊園中改變內部設置。這個問題不應該是「我如何擊敗谷歌瀏覽器的防禦/安全」,而是「我怎麼會*在Google Chrome瀏覽器中永久地改變設置」這是一個谷歌瀏覽器問題,而不是C#/文件系統類型的問題我當然不知道如何修改谷歌瀏覽器 – Servy 2012-04-06 20:08:38
如果你確實成功的保護了你的偏好,那Chrome瀏覽器用戶將永遠無法再改變一個設置...... – 2012-04-06 20:20:16