[英]How can I read the rendered HTML of the current page in Internet Explorer using C#?
[英]How to change home page in Internet Explorer using C#?
是否可以在C#應用程序的Internet Explorer中更改主頁? 其他瀏覽器(Firefox,Chrome)的解決方案也不錯。
好吧,對於IE,您必須設置注冊表項:
HKCU\Software\Microsoft\Internet Explorer\Main\Start Page
對於firefox,您將需要編輯js文件: prefs.js
。 可以在以下位置找到: C:\\Users\\ [USERNAME]\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\ [User Subfolder]
Chrome,將其數據存儲在Preferences
文件中的C:\\Users\\<username>\\AppData\\Local\\Chromium\\User Data\\Default
文件夾中。 這是JSON格式。 編輯它應該沒問題
Internet Explorer的主頁保存在HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main
的“ Start Page
注冊表項中(根據此 ),因此您可以使用Microsoft.Win32
的Registry
類(從此示例開始 )進行設置:
RegistryKey startPageKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main", true);
startPageKey.SetValue("Start Page", "http://stackoverflow.com");
startPageKey.Close();
恐怕其他人一無所知。
是的你可以。 主頁存儲在注冊表中。 只要您的C#程序有權修改注冊表,您就應該能夠將此條目更改為所需的任何頁面。
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main]
“Start Page”=”http://www.yourwebsite.com/”
Firefox不會將主頁存儲在注冊表中,因為它在$ APPDATA \\ Mozilla \\ Firefox \\ Profiles下具有不同的配置文件。[配置文件名稱]您需要讀取的文件是prefs.js,並且該行:user_pref(“ browser.startup 。主頁”, .... );
要獲取默認配置文件,您需要閱讀$ APPDATA \\ Mozilla \\ Firefox \\ profiles.ini。 您必須循環瀏覽每個[Profile#]直到Default = 1,然后才能使用Path = ...獲取您的配置文件名稱。
如果您想讓我將其放入一個函數中(聽起來也是個好主意),或者如果您想創建一個函數,請在Wiki上進行設置。
-斯圖
來自專家交易平台的未經測試的代碼
public static void SetMozilla(string strURL)
{
try
{
string strSystemUname = Environment.UserName.ToString().Trim();
string systemDrive = Environment.ExpandEnvironmentVariables("%SystemDrive%");
string strDirectory = "";
string strPrefFolder = "";
if (Directory.Exists(systemDrive + "\\Documents and Settings\\" + strSystemUname + "\\Application Data\\Mozilla\\Firefox\\Profiles"))
{
strDirectory = systemDrive + "\\Documents and Settings\\" + strSystemUname + "\\Application Data\\Mozilla\\Firefox\\Profiles";
}
else if (Directory.Exists(systemDrive + "\\WINDOWS\\Application Data\\Mozilla\\Firefox\\Profiles"))
{
strDirectory = systemDrive + "\\WINDOWS\\Application Data\\Mozilla\\Firefox\\Profiles";
}
if (strDirectory.Trim().Length != 0)
{
System.IO.DirectoryInfo oDir = new DirectoryInfo(strDirectory);
//System.IO.DirectoryInfo[] oSubDir;
//oSubDir = oDir.GetDirectories(strDirectory);
foreach (DirectoryInfo oFolder in oDir.GetDirectories())
{
if (oFolder.FullName.IndexOf(".default") >= 0)
{
strPrefFolder = oFolder.FullName;
CreatePrefs(strURL, strPrefFolder);
}
}
}
}
catch
{ }
}
private static void CreatePrefs(string strURL, string strFolder)
{
StringBuilder sbPrefs = new StringBuilder();
sbPrefs.Append("# Mozilla User Preferences\n\r");
sbPrefs.Append("/* Do not edit this file.\n\r*\n\r");
sbPrefs.Append("* If you make changes to this file while the application is running,\n\r");
sbPrefs.Append("* the changes will be overwritten when the application exits.,\n\r*\n\r");
sbPrefs.Append("* To make a manual change to preferences, you can visit the URL about:config\n\r");
sbPrefs.Append("* For more information, see http://www.mozilla.org/unix/customizing.html#prefs\n\r");
sbPrefs.Append("*/\n\r");
sbPrefs.Append("user_pref(\"app.update.lastUpdateTime.addon-background-update-timer\", 1188927425);\n\r");
sbPrefs.Append("user_pref(\"app.update.lastUpdateTime.background-update-timer\", 1188927425);\n\r");
sbPrefs.Append("user_pref(\"app.update.lastUpdateTime.blocklist-background-update-timer\", 1188927425);\n\r");
sbPrefs.Append("user_pref(\"app.update.lastUpdateTime.search-engine-update-timer\", 1188927425);\n\r");
sbPrefs.Append("user_pref(\"browser.anchor_color\", \"#0000FF\");\n\r");
sbPrefs.Append("user_pref(\"browser.display.background_color\", \"#C0C0C0\");\n\r");
sbPrefs.Append("user_pref(\"browser.display.use_system_colors\", true);\n\r");
sbPrefs.Append("user_pref(\"browser.formfill.enable\", false);\n\r");
sbPrefs.Append("user_pref(\"browser.history_expire_days\", 20);\n\r");
sbPrefs.Append("user_pref(\"browser.shell.checkDefaultBrowser\", false);\n\r");
sbPrefs.Append("user_pref(\"browser.startup.homepage\", \"" + strURL +"\");\n\r");
sbPrefs.Append("user_pref(\"browser.startup.homepage_override.mstone\", \"rv:1.8.1.6\");\n\r");
sbPrefs.Append("user_pref(\"browser.visited_color\", \"#800080\");\n\r");
sbPrefs.Append("user_pref(\"extensions.lastAppVersion\", \"2.0.0.6\");\n\r");
sbPrefs.Append("user_pref(\"intl.charsetmenu.browser.cache\", \"UTF-8, ISO-8859-1\");\n\r");
sbPrefs.Append("user_pref(\"network.cookie.prefsMigrated\", true);\n\r");
sbPrefs.Append("user_pref(\"security.warn_entering_secure\", false);\n\r");
sbPrefs.Append("user_pref(\"security.warn_leaving_secure\", false);\n\r");
sbPrefs.Append("user_pref(\"security.warn_submit_insecure\", false);\n\r");
sbPrefs.Append("user_pref(\"security.warn_submit_insecure.show_once\", false);\n\r");
sbPrefs.Append("user_pref(\"spellchecker.dictionary\", \"en-US\");\n\r");
sbPrefs.Append("user_pref(\"urlclassifier.tableversion.goog-black-enchash\", \"1.32944\");\n\r");
sbPrefs.Append("user_pref(\"urlclassifier.tableversion.goog-black-url\", \"1.14053\");\n\r");
sbPrefs.Append("user_pref(\"urlclassifier.tableversion.goog-white-domain\", \"1.23\");\n\r");
sbPrefs.Append("user_pref(\"urlclassifier.tableversion.goog-white-url\", \"1.371\");\n\r");
StreamWriter writer = new StreamWriter(strFolder + "\\prefs.js");
writer.Write(sbPrefs.ToString());
writer.Close();
writer.Dispose();
GC.Collect();
}
其他來源
IE:編輯注冊表項HKEY_CURRENT_USER \\ Software \\ Microsoft \\ Internet Explorer \\ Main \\ Start Page
Firefox: 在配置文件文件夾中找到設置 (您需要解析文件)
Chrome:在偏好設置文件中找到默認的“主頁”設置: C:\\Users\\%USERNAME%/AppData\\AppData\\Local\\Google\\Chrome\\User Data\\Default
對於注冊表,請使用.NET RegistryKey類。 對於文件,您將需要解析文件並對其進行修改。
除上述答案外,如果有適當的組策略,則可能需要檢查以下內容:HKCU \\ Software \\ Policies \\ Microsoft \\ Internet Explorer \\ Main \\ Start Page
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.