Enable Internet Connection Sharing programmatically

走远了吗. 提交于 2019-12-13 15:09:14

问题


I can do it manually by right-clicking on a network connection, opening the Sharing tab, clicking on the "Allow other network users to connect through this computer's Internet connection" check box, and selecting a "Home networking connection".

While poking around this problem I have found multiple sets of COM interfaces:

1) Internet Connection Sharing and Internet Connection Firewall Interfaces with INetSharingManager

Its documentation says:

Internet Connection Firewall may be altered or unavailable in subsequent versions. Instead, use the Windows Firewall API.

Moreover, the INetSharingConfiguration.EnableSharing method does not look like it corresponds the procedure described above because its arguments don't include the "Home networking connection".

2) Windows Firewall for Windows XP with SP2 Interfaces

Its documentation references us further:

For Windows Vista and later, use of the Windows Firewall with Advanced Security API is recommended.

3) Windows Firewall with Advanced Security API

There are only the following interfaces: INetFwPolicy2, INetFwProduct, INetFwProducts, INetFwRule, INetFwRule2, INetFwRule3, INetFwRules, INetFwServiceRestriction. Does not look very promising.

Now I'm lost. Which API should I use on Windows 7?


回答1:


utapyngo

Which is your final choice?

http://social.msdn.microsoft.com/Forums/en-tw/windowssdk/thread/19f7581d-29c7-4109-85d4-6a79ee4d1577

"I was able to find the solution. You have to enable the public interface on the adapter you are connecting to and enable sharing on the private interface for the adapter you want to be able to use for the network."




回答2:


The access violation only occurs on Win 10 Anniversary Update if the call is made by a 32bit program on a 64bit OS. It works with 32 bit program on 32bit OS or 64bit program on 64bit OS



来源:https://stackoverflow.com/questions/12294820/enable-internet-connection-sharing-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!