0

Is it possible to change Mobile Broadband device settings via WMI or via the Registry?

I'm trying to create a simple interface that'll run on Windows 10 (eventually running it on Windows 7, 8, and XP Embedded) to change just a few settings, "Connect Automatically" and "Allow Roaming".

After doing some research on the Internet and here at SO: C# Read Windows Mobile Broadband connection properties I think I can do this via WMI or a registry edit, but I'm just not seeing it. The Win32_NetworkAdapter class doesn't appear to provide the right facilities to do this.

I've tried using ProcMon to view the registry edits, but I'm having trouble nailing it down.

Community
  • 1
  • 1
Gorlon
  • 23
  • 5

1 Answers1

0

On Windows 7, the best way I have found to do this is by creating a process which calls netsh.exe with the appropriate arguments. I'm not sure how different this would be on Windows 10.

Here's a console app that retrieves some data.

    /// <summary>
    /// The process instance used to execute netsh.
    /// </summary>
    private static readonly Process NetshProcess = new Process
                                             {
                                                 StartInfo =
                                                     {
                                                         FileName = "netsh.exe",
                                                         RedirectStandardOutput = true,
                                                         UseShellExecute = false
                                                     }
                                             };

    /// <summary>
    /// The main program.
    /// </summary>
    /// <returns>
    /// Nonzero if error.
    /// </returns>
    public static int Main()
    {
        // The first step is to get the subscriber ID.
        NetshProcess.StartInfo.Arguments = "mbn show ready *";
        var netshResultStrings = RunNetShProcess();
        var subIdStr = netshResultStrings.ElementAtOrDefault(5);
        var iccIdStr = netshResultStrings.ElementAtOrDefault(6);
        string lastValue;
        if (subIdStr == null || (lastValue = subIdStr.Trim(' ').Split(':').LastOrDefault()) == null)
        {
            throw new Exception("Could not determine Subscriber ID.");
        }

        var subscriberIdStr = lastValue.Trim(' ');
        Console.WriteLine("The subscriber ID is " + subscriberIdStr);
    }

    /// <summary>
    /// Run the netsh process.  StartInfo.Arguments for NetshProcess must be properly set prior to making this call. 
    /// </summary>
    /// <returns>
    /// An string array containing one element for each line of text returned by netsh.
    /// </returns>
    private static string[] RunNetShProcess()
    {
        NetshProcess.Start();
        var netshResult = NetshProcess.StandardOutput.ReadToEnd();
        if (!NetshProcess.WaitForExit(10000))
        {
            throw new Exception("Netsh command '" + NetshProcess.StartInfo.Arguments + "' did not exit.");
        }

        var netshResultStrings = netshResult.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
        return netshResultStrings;
    }