0

I am trying to spin up mobile hotspot on a windows 10 laptop using a c# program.The requirement is similar to this, but I wont be able to use the NetworkOperatorTetheringManager class since it needs the device to be connected to a wifi network. The ConnectionProfile returned in the below program will be null if not connected to a network.

ConnectionProfile connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
NetworkOperatorTetheringManager tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(connectionProfile);

I know it is possible since there is an app on windows store, called Hotspot Lite which does this. It is possible to start a mobile hotspot using this app without having to be connected to a wifi network.

I am looking for a solution using the windows apis, more specifically using the Windows WiFiDirect api. Appreciate any answer pointing in the right direction.

wardaddy
  • 383
  • 1
  • 4
  • 16
  • You have to use WinRT WiFi Direct API. Or you can simple use WiFi Framework (https://www.btframework.com/wififramework.htm) – Mike Petrichenko Mar 04 '20 at 07:56
  • Thanks for the reply @MikePetrichenko . Do you have any docs other than the general windows doc for wifi direct? – wardaddy Mar 04 '20 at 08:54
  • Depends on what kind of doc you need. How to use WinRT? No, we do not have such docs. Or? – Mike Petrichenko Mar 04 '20 at 09:23
  • Any document detailing how the windows mobile hotspot can be controlled programmatically would do! – wardaddy Mar 04 '20 at 13:51
  • It all described in Microsoft documentation. Refer to WiFi Direct WinRT (UWP) API. – Mike Petrichenko Mar 04 '20 at 15:38
  • @MikePetrichenko could you provide any information as to how the windows mobile hotspot functions? I can in fact create a hotspot using `WiFiDirectAdvertisementPublisher` class, but it does not toggle the inbuilt windows hotspot. I would like to directly control this functionality. – wardaddy Mar 05 '20 at 07:26
  • It does. You mixed up 2 different things: Windows standard application for hotspot and hotspot (hosted network) as itself. – Mike Petrichenko Mar 05 '20 at 09:11
  • I also forgot to say that you have use ICS (or Windows Firewall) API to share your existing internet connection with just created SoftAP. – Mike Petrichenko Mar 05 '20 at 09:16
  • @MikePetrichenko I am sorry, do you mean it is possible to toggle the standard windows hotspot using `WiFiDirectAdvertisementPublisher` class? – wardaddy Mar 05 '20 at 10:11
  • No, its not possible. But the build-in application (when you click Mobile Hotspot button) calls to WiFiDirectAdvertisementPublisher to create SoftAP and to ICS to share internet connection. Then it turns on icon. Update: probably you can call to the build-in app as well but it requires some reverse engeneering to find out which app is responsible for that and how to pass params to it. – Mike Petrichenko Mar 05 '20 at 11:18
  • Is it possible to know which application handles the windows hotspot? May be then I could search for a way to configure it. – wardaddy Mar 05 '20 at 12:11
  • The app I mentioned in the question performs the exact requirement I have, If there was anyway to know how it functions my problem will be solved. – wardaddy Mar 05 '20 at 12:17
  • icssvc is responsible for that. IDA64 or any other disassembler will help to know how ti works. – Mike Petrichenko Mar 05 '20 at 13:05
  • Using information obtained from this [site](http://revertservice.com/10/icssvc/) I tried to decompile tetheringservice.dll with dotPeek and failed. I am able to run `net start icssvc` which gives output that the service has started running, but the windows hotspot does not seem to start. – wardaddy Mar 06 '20 at 05:00
  • @MikePetrichenko could you help with actually decompiling icssvc please? – wardaddy Mar 06 '20 at 05:04
  • I afraid no. 1. It is useless because I gave you all the information above how to do what you need without decompilation and 2. Becasue it is long and very expensive process. – Mike Petrichenko Mar 06 '20 at 09:04

1 Answers1

0

I know this is an old question but I really dislike it when people respond "RTFM". Especially with MS documentation which is piss-poor. The first argument to NetworkOperatorTetheringManager.CreateFromConnectionProfile must be a connection profile, but if you aren't connected to the internet the given call will provide null.

So if you don't care about Internet connectivity, just get the list of network adapters and pick an appropriate one. There is probably an ethernet adapter that isn't plugged in, probably named "Ethernet0", so use that :) I'll assume anybody who reads this knows how to loop over a list:

IReadOnlyList<Windows.Networking.Connectiviy.ConnectionProfile> connections = Windows.Networking.Connectivity.NetworkInformation.GetConnectionProfiles();

Disclaimer: this doesn't mean other stuff won't work later on because the adapter isn't connected, it just solves this problem.

Joel Mussman
  • 196
  • 1
  • 5