C#Open Bluetooth Setup Interface

Bluetooth settings related interface, the following are several ways to open through C#to record

Bluetooth Setup Interface

1. Control panel commandsBthprops.cpl

You can use Control Panel Control+Bthprops.cplOr directlyBthprops.cpl.For more commands see: All Run Command Instructions,CMD & CPL: Shortcut System Commands and Control Panel Commands

Bthprops.cplTo open the Bluetooth connection setup interface

1     //Turn on Bluetooth settings
2     var process = new Process {StartInfo = {FileName = "control", Arguments = "bthprops.cpl"}};
3     process.Start();

You can also use files from drive C Bthprops.cplPath Start

C:\Windows\System32\bthprops.cpl

Note: IfBthprops.cplFailed to jump to Bluetooth setup interface, probably because there is no Bluetooth module.

If you decide if you have a Bluetooth network?

You can view the list of network adapters:

 1     /// <summary>
 2     /// Does it contain a Bluetooth adapter
 3     /// </summary>
 4     /// <returns></returns>
 5     public static bool HasBluetoothNetwork()
 6     {
 7         //Get the object of the network interface on the local computer
 8         NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
 9         return adapters.Any(i => i.Name.Contains("Bluetooth"));
10     }

2.win10 setting url

The control panel is the win7 concept.Win10 has a new setup protocol that allows you to quickly access settings/applications through a url. Almost every Settings item has its own URL

  • In the win+R run box, enter the ms-setting s command
  • You can enter the ms-setting s command at the command line
  • You can also enter the ms-setting s command in the Explorer Address bar

The above paths (and of course other ways) open the related settings interface.

Open the Bluetooth setup interface through the C#code:

 1     Process process = new Process();
 2     process.StartInfo.FileName = "cmd.exe";
 3     process.StartInfo.CreateNoWindow = true;//Do not show program window
 4     process.StartInfo.UseShellExecute = false;//Use operating system or not shell start-up
 5     process.StartInfo.RedirectStandardInput = true;//Accept input from caller
 6     process.StartInfo.RedirectStandardOutput = true;//Get output information from caller
 7     process.StartInfo.RedirectStandardError = true;//Redirect Standard Error Output
 8     process.Start();//Start Program
 9     process.StandardInput.WriteLine("start ms-settings:bluetooth &exit");
10     process.StandardInput.AutoFlush = true;
11     string strOuput = process.StandardOutput.ReadToEnd();
12     process.WaitForExit();
13     process.Close();

In UWP, you can navigate to the Bluetooth settings page through API-LaunchUriAsync.

To learn more about LaunchUriAsync, visit Shuigo's blog: LaunchUriAsync in UWP, opens links using default browsers or other applications

1     var uri = new Uri(@"ms-settings:bluetooth");
2     var success = await Windows.System.Launcher.LaunchUriAsync(uri);

Bluetooth Device List

Enter shell:: {28803F59-3A75-4058-995F-4EE5503B023C} from the Explorer address bar to jump to the list of external Bluetooth devices

Of these, 28803F59-3A75-4058-995F-4EE5503B023C is the value in the registry

C#, you can open the Bluetooth setup interface through Process:

1     //Open Bluetooth Search List
2     var process = new Process { StartInfo = { FileName = "Explorer", Arguments = "shell:::{28803F59-3A75-4058-995F-4EE5503B023C}" } };
3     process.Start();

Tags: C# shell network Windows

Posted on Tue, 26 May 2020 11:06:42 -0700 by lamurio