typedef struct tagAdapterInfo
{
string strName; // 适配器名称
string strDriverDesc; // 适配器描述
string strIP; // IP地址
string strNetMask; // 子网掩码
string strNetGate; // 网关
string strDnsSever;
}ADAPTER_INFO;ADAPTER_INFO* pUIData = GetUIData();
string strSetIP="interface ip set address 本地连接 static ";
strSetIP += pUIData->strIP;
strSetIP += " ";
strSetIP += pUIData->strNetMask;
strSetIP += " ";
strSetIP += pUIData->strNetGate;
strSetIP += " ";
strSetIP += "1";
ShellExecute(this->m_hWnd,"open","netsh.exe",strSetIP.c_str(),"",SW_HIDE);
string strSetDNS = "interface ip set dns 本地连接 static ";
strSetDNS += pUIData->strDnsSever;
strSetDNS += " ";
strSetDNS += "primary";
ShellExecute(this->m_hWnd,"open","netsh.exe",strSetDNS.c_str(),"",SW_HIDE);在vc++中,想修改IP地址和dns地址,原来是自动分配的,GetUIData()是把界面的数据
存到结构里,确认数据已经取得成功,并且IP在局域网内没有IP冲突,但是通过ShellExecute
调用netsh.exe的时候 DNS值不能成功设置,找了许久没有找到原因,各位帮忙看看应该什么
没有注意到。还有谁做过这方面的东西,由自动获取IP,变为我指定的IP,DNS的其他方法,请给出详细代码
需要稳定。由注册表更改,然后用DhcpNotifyConfigChange通知IP改变的方式,只能用由原来是指定静态IP
方式,由一个IP改为另一个IP,由自动获取变为静态指定的时候,好像更改不成功。而且我在xp系统下DhcpNotifyConfigChange有时候调用失败
谢谢各位了!
{
string strName; // 适配器名称
string strDriverDesc; // 适配器描述
string strIP; // IP地址
string strNetMask; // 子网掩码
string strNetGate; // 网关
string strDnsSever;
}ADAPTER_INFO;ADAPTER_INFO* pUIData = GetUIData();
string strSetIP="interface ip set address 本地连接 static ";
strSetIP += pUIData->strIP;
strSetIP += " ";
strSetIP += pUIData->strNetMask;
strSetIP += " ";
strSetIP += pUIData->strNetGate;
strSetIP += " ";
strSetIP += "1";
ShellExecute(this->m_hWnd,"open","netsh.exe",strSetIP.c_str(),"",SW_HIDE);
string strSetDNS = "interface ip set dns 本地连接 static ";
strSetDNS += pUIData->strDnsSever;
strSetDNS += " ";
strSetDNS += "primary";
ShellExecute(this->m_hWnd,"open","netsh.exe",strSetDNS.c_str(),"",SW_HIDE);在vc++中,想修改IP地址和dns地址,原来是自动分配的,GetUIData()是把界面的数据
存到结构里,确认数据已经取得成功,并且IP在局域网内没有IP冲突,但是通过ShellExecute
调用netsh.exe的时候 DNS值不能成功设置,找了许久没有找到原因,各位帮忙看看应该什么
没有注意到。还有谁做过这方面的东西,由自动获取IP,变为我指定的IP,DNS的其他方法,请给出详细代码
需要稳定。由注册表更改,然后用DhcpNotifyConfigChange通知IP改变的方式,只能用由原来是指定静态IP
方式,由一个IP改为另一个IP,由自动获取变为静态指定的时候,好像更改不成功。而且我在xp系统下DhcpNotifyConfigChange有时候调用失败
谢谢各位了!
{
BOOL bResult = FALSE;
HINSTANCE hDhcpDll;
DHCPNOTIFYPROC pDhcpNotifyProc;
WCHAR wcAdapterName[256];
MultiByteToWideChar(CP_ACP, 0, lpszAdapterName, -1, wcAdapterName,256); if((hDhcpDll = LoadLibrary("dhcpcsvc")) == NULL)
return FALSE; if((pDhcpNotifyProc = (DHCPNOTIFYPROC)GetProcAddress(hDhcpDll, "DhcpNotifyConfigChange")) != NULL)
if((pDhcpNotifyProc)(NULL, wcAdapterName, TRUE, nIndex, inet_addr(pIPAddress), inet_addr(pNetMask), 0) == ERROR_SUCCESS)
bResult = TRUE; FreeLibrary(hDhcpDll);
return bResult;
}
http://www.vckbase.com/document/viewdoc/?id=851
ShellExecute(this->m_hWnd,"open","netsh.exe",strSetIP.c_str(),"",SW_HIDE);
把方式先改为静态,在用DhcpNotifyConfigChange更改
但是用ShellExecute时候,dns没设置上 ,IP倒是设置成功了