寻找正在连接中的网络连接,并开启网络连接的网络连接共享功能
来源:互联网 发布:win10解压缩软件 编辑:程序博客网 时间:2024/05/16 10:26
寻找正在连接中的网络连接,并开启网络连接的网络连接共享功能。
注意:要设置为管理员权限启动工程。否则EnableSharing会失败。
#include <Windows.h>#include <NetCon.h>#include <locale>#include <stdio.h>#pragma comment(lib,"Iphlpapi.lib")#pragma comment(lib,"Rpcrt4.lib")//GUID//启用、禁用网卡#pragma comment(lib,"ole32.lib")int main(int argc, char* argv[]){INetConnectionManager *pManager=NULL;INetConnection *pConnection=NULL;IEnumNetConnection *pEnum=NULL;ULONG celtFetched;INetSharingManager *pNetSharingManager=NULL;INetConnectionProps *pProps=NULL;INetSharingConfiguration *pConfiguration=NULL;NETCON_PROPERTIES* properties=NULL;NETCON_MEDIATYPE mediatype;setlocale(LC_CTYPE, "");CoInitialize(NULL);CoCreateInstance(CLSID_ConnectionManager, NULL, CLSCTX_SERVER, IID_INetConnectionManager, (void**)&pManager);if(pManager == NULL){printf("获取接受失败,Error:%d\n",GetLastError());return 0;}pManager->EnumConnections(NCME_DEFAULT, &pEnum); while( pEnum->Next(1, &pConnection, &celtFetched) == S_OK ){pConnection->GetProperties(&properties);if(properties->Status == NCS_CONNECTED){if(properties->dwCharacter & NCCF_INCOMING_ONLY == 1){wprintf(L"\"%S\"正处于连接状态,但是此连接无法共享!确保至少有2个网络连接!\n",properties->pszwName);break;}CoCreateInstance(CLSID_NetSharingManager, NULL, CLSCTX_SERVER, IID_INetSharingManager, (void**)&pNetSharingManager);if(pNetSharingManager == NULL){printf("获取接受失败,Error:%d\n",GetLastError());break;}wprintf(L"发现\"%s\"正处于连接状态。尝试开启共享...\n",properties->pszwName);if(properties->MediaType >= NCM_DIRECT && properties->MediaType <=NCM_PPPOE){pNetSharingManager->get_INetSharingConfigurationForINetConnection(pConnection,&pConfiguration);if(pConfiguration && SUCCEEDED(pConfiguration->EnableSharing(ICSSHARINGTYPE_PUBLIC))){wprintf(L"成功设置\"%s\"为共享状态!\n",properties->pszwName);break;}}wprintf(L"设置\"%s\"共享状态失败!Error:%d\n",properties->pszwName,GetLastError());}}if(pManager) pManager->Release();if(pConnection) pConnection->Release();if(pEnum) pEnum->Release();if(pNetSharingManager) pNetSharingManager->Release();if(pConfiguration) pConfiguration->Release();CoUninitialize();return 0;}
- 寻找正在连接中的网络连接,并开启网络连接的网络连接共享功能
- 寻找正在连接中的网络连接
- 寻找正在连接中的网络连接
- CentOs7 开启网络连接
- centos7 开启网络连接
- C++ 网络连接共享
- 网线连接共享网络
- nexus 正在检查网络连接
- [解决网络出现“正在连接”的问题]
- Android-----------判断是否有网络连接并手动开启网络
- j2me中的网络连接
- 网络连接中的心跳
- java中的网络连接
- 网络中的连接设备
- Android中的网络连接
- 网络连接
- 连接网络
- 网络连接
- jni入门教程之HelloWorld
- paip.输入法编程--词频调整原则--发音长度优先
- Java连接Oracle笔记
- 《Windows核心编程》第二讲 Unicode(2)成为符合ANSI和Unicode的应用程序
- java 对数组进行插入删除修改
- 寻找正在连接中的网络连接,并开启网络连接的网络连接共享功能
- uva 10400 Game Show Math
- Android中获取应用程序(包)的信息-----PackageManager的使用(一)
- Android display架构分析
- 适配器模式
- 安卓开发32:Paint 画笔
- 免费 开发资源库 android web
- 裁剪空间法--实现细节
- java反射机制