Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows-7:Disable internet connection sharing on network adapter when it's in hidden state?

I'm trying to share internet over a network adapter on windows-7 using NetConLib.dll.

In order to do this, internet sharing should be disabled on all other network adapters.

In normal cases. I can iterate all the installed network adapters and disable sharing on them. However, sometimes when the network device is unplugged, the adapter is hidden in windows. But it's properties is still present inside windows registry.

I can't even find the adapter in Control Panel. And off course, can't iterate it using the NetConlib library.


Possible scenarios.

  • The easiest way, would be using a windows command to disable internet sharing on all the adapters. Regardless of their visibility.

    Is that possible in anyway ?

  • The second solution is to recover the network adapter from hidden state, so that NetConlib could iterate through it and disable it.

    I tried to find the adapter's properties in windows registry and unhide it, But couldn't find anything.

Any solution?


@erm3nda.

Thank you for the informative answer. Although it didn't fix the problem I'm facing with NetConlib.

SC config correctly shuts down ICS service. But the shared network adapter continues on being flagged as Shared1. So ICS service being turned off doesn't seem to affect the adapters' settings.

Quite interestingly; when you try to share another adapter using windows GUI (Right click on adapter -> Properties -> Share), a message is prompted telling you

"there is another adapter being shared currently, your new adapter will be shared instead". You click ok and it's done.

I've been digging the entire internet the whole afternoon to see if there are other solutions using CMD commands.

Maybe there could be a away to share an adapter with a command. This way windows would handle disabling other adapters. In a similar way as when the GUI is used.


1: Windows tells you which adapter is currently being shared in Control Panel\Network and Internet\Network Connections).

like image 674
Azad Avatar asked Oct 26 '13 17:10

Azad


2 Answers

Possible solution 1: Disable ICS at all. You can stop ICS service, so none of the connections will be at sharing status and will not conflict with NetConLib.dll. (Not sure about the hidden ones, you must try).

You can manage it from command line using: net start SharedAccess or net stop SharedAccess

Also, if you need to disable it from reboot to, must disable service using: sc config SharedAccess start= disabled

Notes and references:

  • Executing sc config will display "start= OPTIONS" and some other. The space below = and option is mandatory. You can check result running services.msc from Run or cmd.
  • Exec net to display OPTIONS. The name of service is on the services.msc list under "Name of the service" label from ICS service.
  • netsh routing is not on Win7 anymore, so you only can start/stop/enable/disable but not enable for a particular Interface. You must set by handMouse... This not work under Win7 ICS into XP system
  • Sc Config command was from this cool documentation i found today.

Possible solution 2: Remove ghost interfaces? I try also around Adapters and interfaces into registry and do not see anything about show/hid/ghost/enabled or similar. I also search here kb 314053 for registry conf.

I can suggeest try Possible solution 1 :) or directly delete hidden/ghost adapters. You can do it by two ways. Devcon remove option will delete also drivers.

Basic usage for find netcards devcon findall =net, also you can devcon findall =net *ndis* to list all ndis cards. Basic usage for remove will be devcon remove =net *ndis* to remove all ndis card type.

I try also enable/disable commands but nothing has change into my network interfaces list. I removed my own wifi card to test it :) Anyway, i didn't notice any option about "Unhide" feature for such devices from conections panel.

NEW EDIT (Too much verbose, right?)

I found a tool called ics-manager from this superuser post. - read answer #3 You can download directly from utapyngo's Git project page.

It's based on .Net Framework 4. Yo must download and run the build.bat to compile both exe's (You got also the C# source). The solution is to get only the compiled IcsManager.exe (command line version) with the only needed library IcsManagerLibrary.dll.

This app is using also NETCONLib.dll, so you can use it, or read the source to see wich is the correct function you need to do it and implement on your development.

If you got problems with the Ip range "192.168.137.1", you can set from Registry permanently, or run netsh interface ipv4 set address name="YOUR-INTERFACE" source=static addr=192.168.2.1 mask=255.255.255.0. You will got ugly errors from launch the netsh interface using tilde or accutes into interfaces name (Spanish default ethernet name is "Conexión de áreal local"... a joke).

Note: You can pack all at once, using first a Bat to call the IcsManager.exe' with the arguments needed, then launch the netsh configure command later from same batch to full configure.

Comment: About the prompt when try to overwrite an shared connection, it's surely because only one could be shared. I also see, they are configured as Public and Home to set the pair, but i can't find where's the registry key...Also make some exports from reg and using Diffs, no lucky. I got stuck at diffs and start to search "ICS C++ and C#" on Google, then found it.

Extra: I got the netsh it into a bat, and it's launched for Windows Task when a Ethernet cable is plugged (Here is the howto) in order to use with Android Reverse Tethering. As you can see, im too interesting into your question because it makes me research better and also learned a lot.

Sorry about my bad English. Im not. Regards.

like image 172
m3nda Avatar answered Sep 27 '22 17:09

m3nda


I found that by going into Device Manager, you can show the Hidden Devices and try to disable the internet sharing on the adapters.

Hopefully this is near what you are asking. Good luck!

Atm

Source: http://msdn.microsoft.com/en-us/library/windows/hardware/ff553955%28v=vs.85%29.aspx

like image 24
Amealy Avatar answered Sep 27 '22 18:09

Amealy