如何防止新连接出现网络位置对话框(家庭、工作、公共)?

发布于 2024-11-17 10:18:28 字数 1007 浏览 2 评论 0原文

我编写了一个软件,如果连接尚不存在,则使用 USB 3G 适配器连接到互联网。

当软件加载时,它会检测互联网是否可用,如果不可用,则创建拨号连接(通过 RAS),然后进行拨号。

如果第一次发生这种情况,则会出现网络位置对话框,要求用户选择是家庭、工作还是公共网络。

无论如何,我可以以编程方式设置连接的网络位置,或者甚至告诉 Windows 不要显示对话框并自动将位置设置为公共?

干杯

加文

编辑:为斯科特M

public bool Connect(bool monitorSignalUpdates)
{
    RasPhoneBook rpb = new RasPhoneBook();
    rpb.Open(true);
    if (!rpb.Entries.Contains("3G Connection"))
    {
        rpb.Entries.Add(RasEntry.CreateBroadbandEntry("3G Connection", RasDevice.GetDeviceByName("HUAWEI Mobile Connect - 3G Modem", RasDeviceType.Modem), true));
    }
    _rd = new RasDialer();
    _rd.EntryName = "3G Connection";
    _rd.PhoneNumber = "*99#";
    try
    {
        _rd.Dial();
        if (monitorSignalUpdates)
        {
            _queryPort.DataReceived += new SerialDataReceivedEventHandler(_queryPort_DataReceived);
        }
        return true;
    }
    catch (Exception ex)
    {
        int i = 99;
    }
    return false;
}

I've written a piece of software that uses an USB 3G Dongle to connect to the internet if a connection doesn't already exist.

When the software loads, it detects whether the internet is available and if not, then creates a dial up connection (via RAS) and then dials it.

If this happens for the first time, the network location dialog comes up asking the user to select whether it's home, work or public.

Is there anyway, I can either programatically set the network location of a connection, or even tell windows not to show the dialog and automatically set the location to public?

Cheers

Gavin

Edit: For ScottM

public bool Connect(bool monitorSignalUpdates)
{
    RasPhoneBook rpb = new RasPhoneBook();
    rpb.Open(true);
    if (!rpb.Entries.Contains("3G Connection"))
    {
        rpb.Entries.Add(RasEntry.CreateBroadbandEntry("3G Connection", RasDevice.GetDeviceByName("HUAWEI Mobile Connect - 3G Modem", RasDeviceType.Modem), true));
    }
    _rd = new RasDialer();
    _rd.EntryName = "3G Connection";
    _rd.PhoneNumber = "*99#";
    try
    {
        _rd.Dial();
        if (monitorSignalUpdates)
        {
            _queryPort.DataReceived += new SerialDataReceivedEventHandler(_queryPort_DataReceived);
        }
        return true;
    }
    catch (Exception ex)
    {
        int i = 99;
    }
    return false;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

◇流星雨 2024-11-24 10:18:28

此注册表项控制 Windows 是否提示(“Home/Work/Public”):

HKLM\System\CurrentControlSet\Control\Network\NewNetworkWindowOff

http://technet.microsoft.com/en-us/library/gg252535%28v=ws.10%29.aspx

您可以随时“关闭新网络上的通知”系统托盘 :)

如果你能做到这一点,我确信有一个注册表黑客和/或 PowerShell API 可以做到这一点:

http://technet.microsoft.com/en-us /library/cc725831%28v=ws.10%29.aspx

This registry entry controls whether Windows will prompt for ("Home/Work/Public"):

HKLM\System\CurrentControlSet\Control\Network\NewNetworkWindowOff

http://technet.microsoft.com/en-us/library/gg252535%28v=ws.10%29.aspx

You can always "“Turn off Notification on New Networks” from system tray :)

And if you can do that, I'm sure there's a registry hack and/or a PowerShell API for doing the same:

http://technet.microsoft.com/en-us/library/cc725831%28v=ws.10%29.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文