日期:2014-05-17 浏览次数:21111 次
// using NETCONLib;
public static void EnableInternetConnectionSharing()
{
string connectionToShare = "无线网络连接"; // 需要共享的网络连接
string sharedForConnection = "wifi"; // 共享的家庭网络连接
var manager = new NetSharingManager();
var connections = manager.EnumEveryConnection;
foreach (INetConnection c in connections)
{
var props = manager.NetConnectionProps[c];
var sharingCfg = manager.INetSharingConfigurationForINetConnection[c];
if (props.Name == connectionToShare)
{
sharingCfg.EnableSharing(tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PUBLIC);
}
else if (props.Name == sharedForConnection)
{
sharingCfg.EnableSharing(tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PRIVATE);
}
}
}