Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以编程方式设置Mozilla Firefox的默认主页?_C#_.net - Fatal编程技术网

C# 以编程方式设置Mozilla Firefox的默认主页?

C# 以编程方式设置Mozilla Firefox的默认主页?,c#,.net,C#,.net,我知道如何为Google Chrome和Internet Explorer设置默认主页,但我搜索了Google和Stackoverflow,寻找关于如何使用Mozilla Firefox实现这一点的可能答案,但没有机会 我想知道是否有一种可能的方法可以使用C#以编程方式为Mozilla Firefox浏览器设置默认起始页(但我不知道Firefox在哪里存储其主页..) 如何通过编程设置/更改Mozilla Firefox的默认主页 您可能需要使用控制台命令来查找包含主页URL的文件 我要尝试的第

我知道如何为Google Chrome和Internet Explorer设置默认主页,但我搜索了Google和Stackoverflow,寻找关于如何使用Mozilla Firefox实现这一点的可能答案,但没有机会

我想知道是否有一种可能的方法可以使用C#以编程方式为Mozilla Firefox浏览器设置默认起始页(但我不知道Firefox在哪里存储其主页..)

如何通过编程设置/更改Mozilla Firefox的默认主页


您可能需要使用控制台命令来查找包含主页URL的文件

我要尝试的第一件事是:将你的主页设置为不存在的内容,以防止点击具有相同url的cookies,如www.testfirstnamelastname.com

然后转到终端/命令行 和类型

grep-lr“www.testfirstnamelastname.com”*

如果要搜索受管理员保护的目录,请在命令之前添加sudo

希望这对您有所帮助

查看下面的链接


不需要任何代码隐藏。

您需要做的是以编程方式编辑Firefox用户配置文件中的prefs.js文件

可以在目录C:\Users\[USERNAME]\AppData\Roaming\Mozilla\Firefox\Profiles\[某些子文件夹]中找到它

您需要添加或编辑如下所示的行:
用户pref(“browser.startup.homepage”,“www.google.com”)

我知道问题已经得到了回答,但也许下一个程序员需要一个来源

 string firefox = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Mozilla\\Firefox\\Profiles");
        if (Directory.Exists(firefox))
        {
            FileInfo di = new DirectoryInfo(firefox).GetDirectories()[0].GetFiles("prefs.js")[0];
            StreamReader sr = di.OpenText();
            RichTextBox rb = new RichTextBox();
            rb.Text = sr.ReadToEnd();
            sr.Close();
            string[] s = rb.Lines;
            for (int i = 0; i < rb.Lines.Length; i++)
            {
                if (rb.Lines[i].StartsWith("user_pref(\"browser.startup.homepage\""))
                {
                    s[i] = "user_pref(\"browser.startup.homepage\", \"http:\\\\www.somesite.com\");";
                    break;
                }
            }
            File.Delete(di.FullName);
            File.WriteAllLines(di.FullName, s);
        }
string firefox=Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),“Mozilla\\firefox\\Profiles”);
if(Directory.Exists(firefox))
{
FileInfo di=new DirectoryInfo(firefox).GetDirectories()[0].GetFiles(“prefs.js”)[0];
StreamReader sr=di.OpenText();
RichTextBox rb=新的RichTextBox();
rb.Text=sr.ReadToEnd();
高级关闭();
字符串[]s=rb.行;
对于(int i=0;i

这将改变firefox主页。我希望我能帮助别人

我在windows上工作,而不是linux:)有没有可能在windows 7下搜索文件中的字符串?简单:下载这个程序,它将帮助你在任何地方找到reg exp和字符串(这节省了很多时间)@ShikataGaNai C#是一种服务器端语言。。。您认为这将如何改变客户端?您正在使用web应用程序或windows窗体?@9ball我只是想开发一个文件,在执行时更改当前计算机上mozilla firefox的默认主页。@ShikataGaNai我的错。出于某种原因,我假设是web应用程序而不是win表单。拉维亚说得很好,我知道这是一个老生常谈的答案,但我试过了,它看起来不起作用。有什么提示吗?对我有用。您是否尝试过单步执行代码,可能您的Firefox Pref位于不同的位置。