当前位置: 代码迷 >> 综合 >> C++修改WIN10的ip、子网掩码、网关、DNS
  详细解决方案

C++修改WIN10的ip、子网掩码、网关、DNS

热度:86   发布时间:2023-10-22 23:11:06.0

代码

	if (bDHCP){
    string strParameter;strParameter ="netsh interface ip set address name=\"本地连接\" source=dhcp";WinExec(strParameter.c_str(), SW_HIDE);strParameter.clear();strParameter = "netsh interface ip set dns name=\"本地连接\" source=dhcp";WinExec(strParameter.c_str(), SW_HIDE);}else{
    string strParameter;strParameter="netsh interface ip set address name=\"本地连接\" static ";strParameter += T2A(pIPAddress);strParameter += " ";strParameter += T2A(pNetMask);strParameter += " ";strParameter += T2A(pNetGate);strParameter += " ";strParameter += "1";if (WinExec(strParameter.c_str(), SW_HIDE) > 32)printf("Execute Command Successfully\r\n");elseprintf("Fail To Execute Command\r\n");strParameter="netsh interface ip set dns name=\"本地连接\" source=static addr=";strParameter += T2A(pDNS);strParameter += " register = primary";WinExec(strParameter.c_str(), SW_HIDE);strParameter = "netsh interface ip add dns name=\"本地连接\" addr=114.114.115.115";}//2020/1/14 通过c++执行cmd命令来修改win10的ip、子网掩码、网关、DNS//烂笔头
  相关解决方案