Eugene Garbuzov
Eugene Garbuzov

Reputation: 333

Turn off Wi-Fi via C# on Windows 10

Is there a way to turn off Wi-Fi on Windows 10 via C# as if I pressed that button in Internet access menu (or Action Center) as on the image below?

Forgot to say. I am writing a WPF application. Will these methods work on it? I've tried them, but it seems like I don't have a reference for some library.

Upvotes: 4

Views: 4517

Answers (1)

AleFranz
AleFranz

Reputation: 771

First of all you need to request access to be able to modify the radio with WiFiAdapter.RequestAccessAsync(), furthermore you get the radios with Radio.GetRadiosAsync() and check the one with Kind as WiFi, finally you disable it with SetStateAsync(RadioState.Off).

var access = await WiFiAdapter.RequestAccessAsync();
if (access == WiFiAccessStatus.Allowed)
{
     var radios = await Radio.GetRadiosAsync();
     foreach (var radio in radios)
     {
          if (radio.Kind == RadioKind.WiFi)
          {
              await radio.SetStateAsync(RadioState.Off);
          }
      }
}

Upvotes: 1

Related Questions