wince6下不重启改IP

4 篇文章 0 订阅

BOOL CIpSetDlg::RegSetIP(CString pIPAddress,CString pNetMask,CString pNetGate)//静态更改注册表信息
{
HKEY hKey;
CString strKeyName =L"COMM//PCI//R60401//Parms//TCPIP//";
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
    strKeyName,
    0,
    KEY_WRITE,
    &hKey) != ERROR_SUCCESS)
  return FALSE;

WCHAR mszIPAddress[100]={0};
WCHAR mszNetMask[100]={0};
WCHAR mszNetGate[100]={0};
wcsncpy(mszIPAddress,pIPAddress.GetBuffer(pIPAddress.GetLength()),pIPAddress.GetLength());
wcsncpy(mszNetMask,pNetMask.GetBuffer(pNetMask.GetLength()),pNetMask.GetLength());
wcsncpy(mszNetGate,pNetGate.GetBuffer(pNetGate.GetLength()),pNetGate.GetLength());
pIPAddress.ReleaseBuffer();
pNetMask.ReleaseBuffer();
pNetGate.ReleaseBuffer();
int nIP, nMask, nGate;
nIP = wcslen(mszIPAddress);
nMask = wcslen(mszNetMask);
nGate = wcslen(mszNetGate);
DWORD dhcpvalue=0x0;
RegSetValueEx(hKey,L"EnableDHCP", 0, REG_DWORD,(LPBYTE)&dhcpvalue,4);
//RegSetValueEx(hKey,L"DhcpIPAddress", 0, REG_MULTI_SZ,(LPBYTE)mszIPAddress,nIP*2);
RegSetValueEx(hKey,L"IPAddress", 0, REG_MULTI_SZ,(LPBYTE)mszIPAddress,nIP*2);
//RegSetValueEx(hKey,L"DhcpSubnetMask", 0, REG_MULTI_SZ,(LPBYTE)mszNetMask, nMask*2);
RegSetValueEx(hKey,L"SubnetMask", 0, REG_MULTI_SZ,(LPBYTE)mszNetMask, nMask*2);
//RegSetValueEx(hKey,L"DhcpDefaultGateway", 0, REG_MULTI_SZ,(LPBYTE)mszNetGate, nGate*2);
RegSetValueEx(hKey,L"DefaultGateway", 0, REG_MULTI_SZ,(LPBYTE)mszNetGate, nGate*2);
//RegFlushKey(hKey);
RegCloseKey(hKey);
return TRUE;
}
BOOL CIpSetDlg::RegAutoSetIP()//dhcp自动获得IP注册表设置
{
HKEY hKey;
CString strKeyName =L"COMM//PCI//R60401//Parms//TCPIP//";
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
    strKeyName,
    0,
    KEY_WRITE,
    &hKey) != ERROR_SUCCESS)
  return FALSE;
DWORD dhcpvalue=0x1;
RegSetValueEx(hKey,L"EnableDHCP", 0, REG_DWORD,(LPBYTE)&dhcpvalue,4);
RegCloseKey(hKey);
return TRUE;
}
BOOL CIpSetDlg::SetNewDhcpIP()//动态捕获IP
{
UpdateData(true);

ULONG   context;  
    ULONG   Inst;  
IPAddr   NewIP;  
    IPAddr   NewMask;
DWORD dwIfIndex;
char buf[256];
IP_ADAPTER_INDEX_MAP   AdaptMap;
GetAdapterIndex(L"PCI//R60401",&dwIfIndex);
AdaptMap.Index=dwIfIndex;
wcscpy(AdaptMap.Name,L"PCI//R60401");
IpReleaseAddress(&AdaptMap);
DeleteIPAddress(AdaptMap.Index+2);//删除静态的IP
IpRenewAddress(&AdaptMap);
return true;
}
BOOL CIpSetDlg::SetNewIP()//静态设置IP加到列表
{

UpdateData(true);

ULONG   context;  
    ULONG   Inst;  
IPAddr   NewIP;  
    IPAddr   NewMask;
DWORD dwIfIndex;
char buf[256];
IP_ADAPTER_INDEX_MAP   AdaptMap;
GetAdapterIndex(L"PCI//R60401",&dwIfIndex);
AdaptMap.Index=dwIfIndex;
wcscpy(AdaptMap.Name,L"PCI//R60401");
memset(buf,0,256);
    wcstombs(buf,m_ip,m_ip.GetLength());//宽字节转多字节
NewIP=inet_addr(buf);
memset(buf,0,256);
wcstombs(buf,m_netmask,m_netmask.GetLength());//宽字节转多字节
NewMask=inet_addr(buf);
IpReleaseAddress(&AdaptMap);

AddIPAddress(NewIP,NewMask,AdaptMap.Index,&context,&Inst);
DeleteIPAddress(context-1);//删除上一次的IP
//IpRenewAddress(&AdaptMap);
return true;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值