windows 如何使用 C++ 在 IE、Firefox、Chrome 和 Safari 中将网站设置为主页?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4074063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:31:32  来源:igfitidea点击:

How set a website as homepage in IE, Firefox, Chrome and Safari with C++?

c++cwindowsfirefoxbrowser

提问by xRobot

Is there a way to set a website like google.com as homepage through C++ or C ? How ?

有没有办法通过 C++ 或 C 将像 google.com 这样的网站设置为主页?如何 ?

回答by HostileFork says dont trust SE

Not sure what your motive is, but I don't think of this as something I want any code on my system to be setting out from under me. It sounds like the kind of thing adware/malware would do to your grandparents (who wouldn't know how to fix it once it's set). Note the negative comments when the question was asked of how to do it from JavaScript:

不确定你的动机是什么,但我不认为这是我希望我系统上的任何代码从我下面开始的东西。这听起来像是广告软件/恶意软件会对您的祖父母做的事情(一旦设置,他们就不会知道如何修复它)。当被问及如何从 JavaScript 做到这一点时,请注意负面评论:

How can I set default homepage in FF and Chrome via javascript?

如何通过 javascript 在 FF 和 Chrome 中设置默认主页?

It's better to point people at instructions for doing it themselves. Remind with a banner which says "Make us your homepage!", and link to something along these lines:

最好向人们指出自己做的说明。用横幅提醒“让我们成为您的主页!”,并链接到以下内容:

http://www.makeuseof.com/tag/how-to-change-your-homepage-in-5-browsers/

http://www.makeuseof.com/tag/how-to-change-your-homepage-in-5-browsers/

If not for the aesthetic reasons, there are technical reasons not to try and write code for it. Each browser stores this information in its own place. In IE's case, there appears to be a registry setting:

如果不是出于审美原因,也有技术原因不尝试为它编写代码。每个浏览器都将此信息存储在自己的位置。在 IE 的情况下,似乎有一个注册表设置

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Start Page

So you'd use calls to the Windows Registry APIto query it and set it. But Firefox doesn't save this in the registry, it saves it in something called prefs.jsand you'll be looking for:

因此,您将使用对Windows 注册表 API 的调用来查询和设置它。但是 Firefox 不会将其保存在注册表中,而是将其保存在名为的内容中prefs.js,您将查找:

user_pref("browser.startup.homepage", .... );

Then there's Opera, Safari, Chrome, etc. All told, better to just give people directions and put them in control of their experience!

然后是 Opera、Safari、Chrome 等。总而言之,最好只是给人们指明方向并让他们控制他们的体验!

回答by asvignesh

Imports Microsft.Win32
...

Module Util
    Sub SetHomePage(Dim theUrl As String)
        Registry.SetValue("HKCU\Software\Microsoft\Internet Explorer\Main", "Start Page", theUrl)
    End Sub
End Module

回答by pmg

Yes.

是的。

Find the way each browser saves its configuration to disk and edit that (*). It may be a file, or records in a database, or some data in a central registry, or some other scheme --- the browser documentation should tell you.

查找每个浏览器将其配置保存到磁盘的方式并对其进行编辑 (*)。它可能是一个文件,或者数据库中的记录,或者中央注册表中的一些数据,或者其他一些方案——浏览器文档应该会告诉你。

To open/read/write/save/close a file, the C functions declared in the header <stdio.h>may be helpful.

要打开/读取/写入/保存/关闭文件,标头中声明的 C 函数<stdio.h>可能会有所帮助。

(*) for Firefox it's a file named "prefs.ini" in a directory somewhere under the users home path; there may be more than 1 such file if the user has more than 1 profile.

(*) 对于 Firefox,它是用户主路径下某个目录中名为“prefs.ini”的文件;如果用户有 1 个以上的配置文件,则可能会有 1 个以上的此类文件。