ICS Internet网络共享 整个流程设置
netsh winsock reset netsh int ip reset ipconfig /release ipconfig /renew ipconfig /flushdns
这些命令会重置网络套接字、重置 IP 协议、释放和更新 IP 地址、清除 DNS 缓存,从而恢复网络的正常工作。
https://nc.gznu.edu.cn/info/1022/1107.htm 经典网络故障排查
https://www.cnblogs.com/hukey/p/14927291.html
方法1:(二娃亲测有效)
1、选中“Internet Connection Sharing”这个服务右键,点击属性打开,启动类型选择“自动”,确定保存
https://blog.csdn.net/kongqwesd12/article/details/121020946
2、找到路径:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\SharedAccess下,添加一个注册表子项
3、在空白处右击鼠标,新建“DWORD(32位)值(D)”,名称叫做“EnableRebootPersistConnection”,将数值数据改为1。
方法2:(未测试)
查了下资料,可以通过INetSharingManager来实现,原理很简单: 模拟手工的动作自动化操作。
https://blog.51cto.com/u_15127589/2805660
HRESULT shareNet(INetSharingManager* pNSM, const char* srcName, const char* dstName)
{
INetConnection * pNC = NULL;
INetSharingConfiguration * pNSC = NULL;
IEnumVARIANT * pEV = NULL;
IUnknown * pUnk = NULL;
INetSharingEveryConnectionCollection * pNSECC = NULL;
HRESULT hr = pNSM->get_EnumEveryConnection(&pNSECC);
VARIANT v;
VariantInit(&v); if (!pNSECC)
{
wprintf(L"failed to get EveryConnectionCollection!\r\n"); return NULL;
}
hr = pNSECC->get__NewEnum(&pUnk); if (pUnk)
{
hr = pUnk->QueryInterface(__uuidof(IEnumVARIANT), (void**)&pEV);
pUnk->Release();
}
wprintf(L"----------------------------------------------------------\n"); while (S_OK == pEV->Next(1, &v, NULL))
{ if (V_VT(&v) == VT_UNKNOWN)
{
V_UNKNOWN(&v)->QueryInterface(__uuidof(INetConnection), (void**)&pNC); if (pNC)
{
NETCON_PROPERTIES* pNP = NULL;
pNC->GetProperties(&pNP);
setlocale(LC_ALL, "chs");
wprintf(L"pszwName--%s\n", pNP->pszwName);
wprintf(L"pszwDeviceName--%s\n", pNP->pszwDeviceName);
wprintf(L"Status--%d\n", pNP->Status);
wprintf(L"\n"); //continue;
if (pNP->Status != NCS_CONNECTED) continue;
std::string tmpName = CW2A(pNP->pszwName); //printf("###### |%s| : |%s|\r\n", tmpName.c_str(),(char*)nicName);
hr = pNSM->get_INetSharingConfigurationForINetConnection(pNC, &pNSC); if (!strcmp(tmpName.c_str(), (char*)srcName))
{
printf("**************find nic srcName : %s\r\n", (char*)srcName);
hr = pNSC->DisableSharing();
Sleep(500); //getchar();
hr = pNSC->EnableSharing(ICSSHARINGTYPE_PUBLIC);
}
pNSC->Release();
hr = pNSM->get_INetSharingConfigurationForINetConnection(pNC, &pNSC); if (!strcmp(tmpName.c_str(), (char*)dstName))
{
printf("**************find nic dstName : %s\r\n", (char*)dstName);
hr = pNSC->DisableSharing();
Sleep(500);
hr = pNSC->EnableSharing(ICSSHARINGTYPE_PRIVATE);
}
pNSC->Release();
}
}
} return hr;
}
阅读剩余
THE END