3

I have to check if the Airplane Mode is enabled in Windows 8 and maybe switch its state. I am currently working on a C# .NET 4.0 Windows Forms application but the answers in this question shouldn't be limited by that.

Jader Dias
  • 88,211
  • 155
  • 421
  • 625

2 Answers2

4

Unfortunately, there isn't a programmatic way for Metro apps to change the airplane mode in Windows 8. It is against the Metro guidelines for an application to go outside its sandbox and modify system settings like this without user permission (see the discussion at http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/1ad10725-b1b8-4723-b2c3-861900809e02).

Now, you may be able to figure out the status by using some of the functionality in the Windows.Networking.NetworkOperators namespace. Specifically, check out the MobileBroadbandRadioState and NetworkDeviceStatus enumerations.

Or, you could prompt the user to make the change by explaining how to access the setting using Windows Key + I, Change PC Settings, Wireless, Airplane Mode.

Jennifer Marsman - MSFT
  • 5,167
  • 1
  • 25
  • 24
  • Am I constrained by the Metro Guidelines even when developing traditional desktop apps? – Jader Dias Jul 26 '12 at 16:35
  • 1
    No, the Metro guidelines apply only to Metro apps, not traditional desktop apps. – Jennifer Marsman - MSFT Jul 26 '12 at 17:09
  • So you're saying that while Metro apps can't switch the Airplane Mode programatically, maybe the desktop apps could. – Jader Dias Jul 26 '12 at 17:36
  • 1
    Just assume you are on a plane and a program can turn off Airplane mode automatically. Do you really want to have such a program? I would not think Microsoft will provide an API that can change Airplane mode. – Yongwei Wu Feb 06 '13 at 05:22
2

Here is a code snippet to get the NetworkConnectivityLevel which will likely give you what you need to know. I don't know if there is a way to change it. I would doubt it because you would need to also provide a way to pick a network to connect to.

    public static NetworkConnectivityLevel GetNetworkConnectivityLevel()
    {
        ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();

        var ncl = NetworkConnectivityLevel.None;

        if (profile != null)
        {
            ncl = profile.GetNetworkConnectivityLevel();
        }

        return ncl;
    }
Thomas
  • 3,532
  • 3
  • 20
  • 22