zoukankan      html  css  js  c++  java
  • 转:WinCE6.0 不重启修改IP地址

    采用修改注册表的方式实现:

    在应用程序中修改IP地址的方式:

     1 //////////////////////////////////////////////////////////////////////////
     2 // Set IP Address, Mask and Gateway 
     3 // Through the registry entry:
     4 // [HKEY_LOCAL_MACHINE/Comm/DM9CE1/Parms/TcpIp]
     5 // IpAddress, String
     6 // SubnetMask, String
     7 // DefaultGateway, String
     8 //////////////////////////////////////////////////////////////////////////
     9 SYSTEMUTILITY_API BOOL SysUtil_IPConfig(LPCWSTR m_StrIPAddress, LPCWSTR m_StrIPMask, LPCWSTR m_StrGate)
    10 {
    11     long lResult = 0;
    12 
    13     HANDLE hIPCEvent = CreateEvent(NULL, TRUE, FALSE, NULL); ;
    14     LPCTSTR    strSubKeyName = _T("Comm//DM9CE1//Parms//TcpIp");
    15     LPCTSTR strAdapterName = _T("DM9CE1");
    16     LPCTSTR strIP = _T("IpAddress");
    17     LPCTSTR strMask = _T("SubnetMask");
    18     LPCTSTR strGate = _T("DefaultGateway");
    19     LPCTSTR strDHCP = _T("EnableDHCP");
    20     DWORD dwValue = 0;
    21 
    22     DWORD dwStatus = NotifyAddrChange(&hIPCEvent, NULL);
    23     if(dwStatus != NO_ERROR)
    24         return FALSE;
    25 
    26     // Change IP Settings
    27     HKEY hKey;
    28     DWORD dwStrLen = 0;
    29     if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, strSubKeyName, 0, 0, &hKey) == ERROR_SUCCESS)
    30     {
    31         dwStrLen = wcslen(m_StrIPAddress) * sizeof(WCHAR);
    32         lResult = RegSetValueEx(hKey, strIP, 0, REG_SZ, (LPBYTE)m_StrIPAddress, dwStrLen);
    33         if(lResult != ERROR_SUCCESS)
    34             return FALSE;
    35 
    36         dwStrLen = wcslen(m_StrIPMask) * sizeof(WCHAR);
    37         lResult = RegSetValueEx(hKey, strMask, 0, REG_SZ, (LPBYTE)m_StrIPMask, dwStrLen);
    38         if(lResult != ERROR_SUCCESS)
    39             return FALSE;
    40 
    41         dwStrLen = wcslen(m_StrGate) * sizeof(WCHAR);
    42         lResult = RegSetValueEx(hKey, strGate, 0, REG_SZ, (LPBYTE)m_StrGate, dwStrLen);
    43         if(lResult != ERROR_SUCCESS)
    44             return FALSE;
    45 
    46         dwStrLen = sizeof(dwValue);
    47         lResult = RegSetValueEx(hKey, strDHCP, 0, REG_DWORD, (LPBYTE)&dwValue, dwStrLen); 
    48         if(lResult != ERROR_SUCCESS)
    49             return FALSE;
    50 
    51         RegCloseKey(hKey);
    52     }
    53 
    54     // Rebind NDIS
    55     if(!RebindNdisAdapter(strAdapterName))
    56         return FALSE;
    57 
    58     // Waiting until they are applied
    59     if(WaitForSingleObject(hIPCEvent, WAIT_TIMEOUT_10S) != WAIT_OBJECT_0)
    60         return FALSE;
    61 
    62     CloseHandle(hIPCEvent);
    63 
    64     return TRUE;
    65 }
  • 相关阅读:
    LDAP2-创建OU创建用户
    GNE: 4行代码实现新闻类网站通用爬虫
    为什么每一个爬虫工程师都应该学习 Kafka
    新闻网页通用抽取器GNEv0.04版更新,支持提取正文图片与源代码
    写了那么久的Python,你应该学会使用yield关键字了
    新闻类网页正文通用抽取器
    为什么Python 3.6以后字典有序并且效率更高?
    为什么你需要少看垃圾博客以及如何在Python里精确地四舍五入
    数据工程师妹子养成手记——数据库篇
    一行js代码识别Selenium+Webdriver及其应对方案
  • 原文地址:https://www.cnblogs.com/killer-xc/p/6692237.html
Copyright © 2011-2022 走看看