以编程方式添加和更改 Windows 网络设置
我想构建一个程序来在用户计算机上设置新的 VPN 网络,然后连接到该网络。
用户将使用 Windows(Vista 或 7)。
我想知道如何以编程方式设置新的 VPN 网络,然后让用户单击按钮即可连接/断开连接。
要设置的网络需要连接到我设置为接收 PPTP 连接的 Linux 服务器,这样这方面的工作就全部完成了。
关于此事的任何帮助都会很棒,因为我已经谷歌了,但没有发现任何真正有帮助的东西:/
I want to build a program to set up a new VPN network on the users machine, and then connect to that network.
The users will be using Windows (Vista or 7).
I am wondering how I would go about setting up a new VPN network programmatically and then have the user connect/disconnect from it at a click of a button.
The network to set up needs to connect to a linux server that I have setup to receive PPTP connections, so that side of it all is done.
ANy help on the matter would be great, as I have Google'd and found nothing that really helps :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 netsh 命令 (a/ k/a“NetShell”)在这里比较合适,因为它可以控制您正在寻找的网络功能。
按原样,它是一个可以交互使用的命令行工具,因此您可以尝试通过 shell 命令创建/启动/控制连接,或者更好的是,您可以 以编程方式挂钩到公共函数。
(不过,我要指出的是,我还没有尝试过对 netsh 进行任何编程控制,所以你只能靠自己了!)
I think the netsh command (a/k/a "NetShell") would be appropriate here, as it can control the networking functions you are looking for.
As-is, it is a command-line tool that can be used interactively, so you could attempt to create/start/control the connections via shell commands--or better yet, you could programatically hook into the public functions.
(I will note, however, that I have not tried any programmatic control of netsh, so you're on your own there!)
我没有看到 netsh 支持创建 VPN 连接。
我发现一种有效的技术是直接创建电话簿条目。在 Windows 7 上,可以在 %appdata%\Microsoft\Network\Connections\pbk\rasphone.pbk 中找到电话簿。在另一台计算机上创建该条目,然后使用该条目以编程方式编辑目标计算机上的 .pbk 文件(它只是一个文本文件)。
请注意,这不会保存任何凭据,因此如果用户需要输入凭据,则仍然需要执行必要的身份验证步骤。
另一种技术是使用API,但我还没有尝试过这种方法。
I don't see that netsh supports creating VPN connections.
One technique I've found that works is to create the phone book entry directly. On Windows 7, the phonebook can be found in %appdata%\Microsoft\Network\Connections\pbk\rasphone.pbk. Create the entry on another machine, then use that entry to programmatically edit the .pbk files on the target machine (it's just a text file).
Note that this won't save any credentials, so if the user is required to enter credentials, there will still be a necessary authentication step.
Another technique would be to use the API, but I haven't yet attempted this approach.