-2

I'm wondering if there is a way other than executing cmd commands in my windows form app to enable or configure an ad hoc network in windows 10?

I'm looking for a direct way like using windows's own libraries which the cmd command for ad hoc (netsh wlan hostednetwork) uses to configure the network.

Note: I don't want to execute cmd commands in my app.

What I have tried:

I've used cmd execution in my app and worked.

command like:

wlan netsh hostednetwork

but I don't want that black cmd console to be displayed over my app frequntly.

Any help will be appreciated.

Jac0231
  • 1
  • 1
  • There are 2 ways to do what you need. If your adapter supports you can use Legacy Hosted Network API. If your adapter does not support legacy mode you should use modern WinRT WiFi Direct Soft AP API. Or use third party libs, let say WiFi Framework – Mike Petrichenko Apr 27 '21 at 17:24

1 Answers1

0

Based on my research, you can refer to the following link to know use winapi to Start the wireless Hosted Network.

User and Application Access to Wireless Hosted Network

However, we find that the function(such as WlanHostedNetworkForceStart) is c++ code.

Therefore, we can add nuget-package Vanara.PInvoke.WlanApi to c# in the winform app.

Then, we can call the code like the following.

using System.Windows.Forms;
using Vanara.PInvoke;
using static Vanara.PInvoke.WlanApi;


private void button1_Click(object sender, EventArgs e)
        {
            WLAN_HOSTED_NETWORK_REASON reason;
            WlanApi.WlanHostedNetworkForceStart(handle,out reason);
      
        }
Jack J Jun
  • 5,633
  • 1
  • 9
  • 27