Search code examples
c#uwpwifi

Bring up a WiFi dialog if network not present


Writing a UWP app and if a network (wired then wireless) is not detected, I would like to bring up the settings dialog that chooses a wireless network.

I can't seem to find any details on the possibility of doing this, and if possible, how to make it happen.


Solution

  • I'm unsure if this is completely what you want but it should work fine.

    A useful link for opening windows settings in UWP apps is THIS

    As it says if the app is a mobile you use: ms-settings-wifi:

    Or for a Desktop/Non-Mobile device use ms-settings:network-wifi

    Note that ms-settings:network-wifi and ms-settings-wifi: open up the main settings window if there is no Wireless Adapter on the device.

    Try launching this application ms-settings:network-wifi in Run (Win+R).

    An example of using this in C# would be

    // The URI to launch
    string uriToLaunch = @"ms-settings:network-wifi";
    
    // Create a Uri object from a URI string 
    var uri = new Uri(uriToLaunch);
    
    // Launch the URI
    async void DefaultLaunch()
    {
       // Launch the URI
       var success = await Windows.System.Launcher.LaunchUriAsync(uri);
    
       if (success)
       {
          // URI launched
       }
       else
       {
          // URI launch failed
       }
    }