精华内容
下载资源
问答
  • Wince中如何修改IP地址

    热门讨论 2012-03-15 15:09:58
    C#操作wince修改IP地址的AIP代码;修改IP地址不需重启即刻生效
  • wince设置ip地址bool SetIpAddress(CString m_strIp,CString m_strMask,CString m_strGateWay){//获得网卡的设备名WCHAR Names[50];DWORD bytes;HANDLE m_hFileHandle = CreateFile(_T("NDS0:"), 0, 0, NULL,OPEN_...

    wince设置ip地址

    bool SetIpAddress(CString m_strIp,CString m_strMask,CString m_strGateWay)

    {

    //获得网卡的设备名

    WCHAR Names[50];

    DWORD bytes;

    HANDLE m_hFileHandle = CreateFile(_T("NDS0:"), 0, 0, NULL,

    OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,

    (HANDLE) INVALID_HANDLE_VALUE);

    if( m_hFileHandle == INVALID_HANDLE_VALUE )

    {

    MessageBox(NULL,_T("获得网卡名时打开设备错误"),NULL,0);

    return false;

    }

    // Get list of adapter names

    if (!DeviceIoControl(m_hFileHandle,

    IOCTL_NDIS_GET_ADAPTER_NAMES,

    NULL,0,

    Names,MAX_PATH,&bytes,NULL))

    {

    MessageBox(NULL,_T("获得网卡名错误"),NULL,0);

    return false;

    }

    DWORD len = wcslen(Names);

    Names[len] = 0;

    Names[len+1] = 0;

    CString strKeyName;

    strKeyName.Format(_T("Comm//%s//Parms//TCPIP"),Names);

    //打开注册表对网卡IP信息对应子健进行修改

    HKEY   hkey;

    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,strKeyName,0,KEY_WRITE,&hkey)   !=   ERROR_SUCCESS)

    {

    MessageBox(NULL,TEXT("打开注册表错误"),NULL,0);

    return false;

    }

    DWORD   value;

    value   =   0;

    WCHAR buffer[50];

    //set   EnableDHCP

    if(RegSetValueEx(hkey,TEXT("EnableDHCP"),0,REG_DWORD,(const   unsigned   char   *)&value,sizeof(DWORD))   !=   ERROR_SUCCESS)

    MessageBox(NULL,TEXT("关闭自动获得IP错误"),NULL,0);

    //set   ip   address

    memset(buffer,0,100);

    memcpy(buffer,m_strIp.GetBuffer(0),m_strIp.GetLength()*2);

    if(RegSetValueEx(hkey,TEXT("IpAddress"),0,REG_MULTI_SZ,(const   unsigned   char   *)buffer, m_strIp.GetLength()*2+2) !=   ERROR_SUCCESS)

    MessageBox(NULL,TEXT("设置IP错误"),NULL,0);

    //set   subnet   mask

    memset(buffer,0,100);

    memcpy(buffer,m_strMask.GetBuffer(0),m_strMask.GetLength()*2);

    if(RegSetValueEx(hkey,TEXT("SubnetMask"),0,REG_MULTI_SZ,(const   unsigned   char   *)buffer, m_strMask.GetLength()*2+2) !=   ERROR_SUCCESS)

    MessageBox(NULL,TEXT("设置子网掩码错误"),NULL,0);

    //set   gateway

    memset(buffer,0,100);

    memcpy(buffer,m_strGateWay.GetBuffer(0),m_strGateWay.GetLength()*2);

    if(RegSetValueEx(hkey,TEXT("DefaultGateway"),0,REG_MULTI_SZ,(const   unsigned   char   *)buffer, m_strGateWay.GetLength()*2+2) !=   ERROR_SUCCESS)

    MessageBox(NULL,TEXT("设置网关错误"),NULL,0);

    RegFlushKey(hkey);

    RegCloseKey(hkey);

    // 重启网卡,不用机器热启动

    HANDLE hNdis = CreateFile(_T("NDS0:"), 0, 0, NULL,

    OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,

    (HANDLE) INVALID_HANDLE_VALUE);

    if( hNdis == INVALID_HANDLE_VALUE )

    {

    MessageBox(NULL,_T( "重启网络驱动时打开设备错误"),NULL,0);

    return false;

    }

    // Send the device command.

    if (!DeviceIoControl( hNdis, IOCTL_NDIS_REBIND_ADAPTER,

    Names, _tcslen( Names) + sizeof( TCHAR ),    // buf contains the name of the

    NULL, 0, NULL, NULL ) )

    {

    MessageBox(NULL,_T( "重启网络驱动错误"),NULL,0);

    }

    CloseHandle( hNdis );

    return true;

    }

    wince的网络配置注册表信息

    首先,必须知道网卡驱动名字。在s3c2410上,名字叫“CS8900”,用工具连接上wince查看他的注册表。你将可以得到下面的东西。

    [HKEY_LOCAL_MACHINE/Comm/CS8900]

    "DisplayName"="CS8900"

    "Group"="NDIS"

    "ImagePath"="CS8900.dll"

    [HKEY_LOCAL_MACHINE/Comm/CS8900/Linkage]

    "Route"=hex(7):/

    43,53,38,39,30,30,31,00,00,00,00

    上面的hex值其实是:CS89001,同样可以在[HKEY_LOCAL_MACHINE/Comm/CS8900]项下面看到关于CS89001的表述。

    [HKEY_LOCAL_MACHINE/Comm/CS89001]

    "DisplayName"="CS8900"

    "Group"="NDIS"

    "ImagePath"="CS8900.dll"

    [HKEY_LOCAL_MACHINE/Comm/CS89001/Parms]

    "BusNumber"=dword:00000000

    "BusType"=dword:00000000

    "InterruptNumber"=dword:0000000a

    "Sysintr"=dword:0000001a

    "DuplexMode"=dword:00000001

    "IoBaseAddress"=dword:a7000300

    "Transceiver"=dword:00000003

    "CardType"=dword:00000001

    [HKEY_LOCAL_MACHINE/Comm/CS89001/Parms/TcpIp]

    "IpAddress"="192.168.1.109"

    "EnableDHCP"=dword:00000000

    "LeaseObtainedLow"=dword:6a806780

    "AutoInterval"=dword:0000012c

    "AutoMask"="255.255.0.0"

    "AutoSubnet"="169.254.0.0"

    "AutoIP"="0.0.0.0"

    "AutoSeed"=dword:00000000

    "PrevReqOptions"=hex:/

    07,01,03,06,0f,2c,2e,2f

    "T2"=dword:000bae0a

    "T1"=dword:0006ac98

    "Lease"=dword:000d5930

    "LeaseObtainedHigh"=dword:01c84915

    "DhcpDNS"=hex(7):/

    31,39,32,2e,31,36,38,2e,31,2e,38,00,00,00,00

    "DhcpDefaultGateway"="0.0.0.0"

    "DhcpServer"="192.168.1.8"

    "DhcpSubnetMask"="255.255.255.0"

    "DhcpIPAddress"="192.168.1.63"

    "AutoCfg"=dword:00000001

    "DefaultGateway"=hex(7):/

    31,39,32,2e,31,36,38,2e,31,2e,38,00,00,00,00

    "DNS"=hex(7):/

    31,39,32,2e,31,36,38,2e,31,2e,31,00,00,00,00

    "Subnetmask"=hex(7):/

    32,35,35,2e,32,35,35,2e,32,35,35,2e,30,00,00,00,00

    "LLInterface"=""

    "UseZeroBroadcast"=dword:00000000

    内容很多,但是我们一般关心的就只有[HKEY_LOCAL_MACHINE/Comm/CS89001/Parms/TcpIp]下的几个。

    "EnableDHCP"=dword:0

    "DefaultGateway"="192.168.1.1"

    "IpAddress"="192.168.1.100"

    "Subnetmask"="255.255.255.0"

    "DNS"="192.168.1.1"

    "DefaultGateway"=hex(7):/

    31,39,32,2e,31,36,38,2e,31,2e,38,00,00,00,00

    "EnableDHCP"--控制DHCP,如果把他的值改为1,那么系统将用DHCP分配IP,设置的IP等信息是没有效果的。也就是自动获取。

    如果"EnableDHCP"为0,那么可以通过"IpAddress","Subnetmask","DefaultGateway"等设置网络信息。其他信息如果有需要自己修改。

    至于修改注册表的编程也不是难事,在wince中有函数可以帮助你完成这件事情。

    RegCreateKeyEx

    RegQueryValueEx

    RegSetValueEx

    RegCloseKey

    其中RegSetValueEx函数可以通过不同的宏写如不同类型的值,比如:

    REG_SZ

    REG_BINARY

    REG_DWORD

    还有更多的,具体看winnt.h头文件。

    已于读取我想就不用说了,自己看看evc的帮助吧。

    DHCP自动获取IP的具体信息相信你也从上面的注册表信息看到了,需要就读取一下。

    PS:注册表操作还有其他函数,根据自己情况用吧。

    展开全文
  • 本人所使用的开发环境是VS2008,开发的系统所在移动终端版本为windows mobile 5.0。由于需要进行身份的验证,...殊不知,WinCE下并没有System.Management,这种方法根本行不通。第二种方法:通过查找注册表来获取M...

    本人所使用的开发环境是VS2008,开发的系统所在移动终端版本为windows mobile 5.0。由于需要进行身份的验证,需要获取移动终端的MAC地址,于是在网上进行搜索,主要看到了三种方法来实现获取MAC地址,现记录如下。

    第一种方法:使用ManagementClass 来获取。

    殊不知,WinCE下并没有System.Management,这种方法根本行不通。

    第二种方法:通过查找注册表来获取MAC地址。

    这是获取注册表地址的代码:

    txtMAC1.Text = reg.ReadValue(YFReg.HKEY.HKEY_LOCAL_MACHINE, @"Comm\DM9CE1\Parms", "SoftwareMacAddress0");

    其他的代码我这里就不列出来了,用这种方法我并没有获取到MAC地址。于是在网上下载了一个注册表查看工具,在移动终端中找,找遍了,发现并没有Comm\DM9CE1\Parms路径,再找其他的路径,都没找到有SoftwareMacAddress节点的。好吧,可能这种方法能获取MAC地址,但是我这个版本的不行。

    第三种方法:通过SendARP获取MAC地址。

    代码如下:

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;

    using System.Collections;

    using System.Diagnostics;

    using System.Runtime.InteropServices;

    using System.IO;

    using System.Security.Cryptography;

    using System.Net;

    namespace WirelessRouteSystem

    {

    class SysInfo

    {

    private static string[] strEncrypt = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP" };

    private static Int32 METHOD_BUFFERED = 0;

    private static Int32 FILE_ANY_ACCESS = 0;

    private static Int32 FILE_DEVICE_HAL = 0x00000101;

    private const Int32 ERROR_NOT_SUPPORTED = 0x32;

    private const Int32 ERROR_INSUFFICIENT_BUFFER = 0x7A;

    private static Int32 IOCTL_HAL_GET_DEVICEID = ((FILE_DEVICE_HAL) << 16) | ((FILE_ANY_ACCESS) << 14) | ((21) << 2) | (METHOD_BUFFERED);

    [DllImport("coredll.dll", SetLastError = true)]

    private static extern bool KernelIoControl(Int32 dwIoControlCode, IntPtr lpInBuf, Int32 nInBufSize, byte[] lpOutBuf, Int32 nOutBufSize, ref Int32 lpBytesReturned);

    [DllImport("Iphlpapi.dll", EntryPoint = "SendARP")]

    public static extern uint SendARP(uint DestIP, uint SrcIP, byte[] pMacAddr, ref uint PhyAddrLen);

    ///

    /// 获取MAC地址

    ///

    ///

    public string GetMac()

    {

    uint ip = 0;

    string mac = string.Empty;

    //取本机IP列表

    IPAddress[] ips = Dns.GetHostEntry(Dns.GetHostName()).AddressList;

    //取本机IP

    byte[] ipp = ips[1].GetAddressBytes();

    ip = (uint)((ipp[0]) | (ipp[1] << 8) | (ipp[2] << 16) | (ipp[3] << 24));

    //取MAC

    byte[] MacAddr = new byte[6];

    uint PhyAddrLen = 6;

    uint hr = SendARP(ip, 0, MacAddr, ref PhyAddrLen);

    if (MacAddr[0] != 0 || MacAddr[1] != 0 || MacAddr[2] != 0 || MacAddr[3] != 0 || MacAddr[4] != 0 || MacAddr[5] != 0)

    {

    mac = MacAddr[0].ToString("X2") + ":" + MacAddr[1].ToString("X2") + ":" + MacAddr[2].ToString("X2") + ":" + MacAddr[3].ToString("X2") + ":" + MacAddr[4].ToString("X2") + ":" + MacAddr[5].ToString("X2");

    }

    return mac;

    }

    ///

    ///获取本机IP

    ///

    ///

    public string GetIpAddress()

    {

    string strHostName = Dns.GetHostName(); //得到本机的主机名

    IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本机IP

    string strAddr = ipEntry.AddressList[1].ToString();

    return strAddr;

    }

    }

    }

    通过 IP Helper API 中的 SendARP 发送 ARP 请求可以用来获取指定IP地址的MAC 地址,简单方便,缺点是不能跨越网关。

    至于获取IP地址,本文已经给出了两种方法,都是通过NET下DNS类中方法获取。

    展开全文
  • 紧跟《注册表中RegSetValueEx用法》文章,自己写了一个测试程序,... 测试程序的功能是,谁知当前WINCE设备的IP地址,包括:子网掩码、默认网关等,并且使设置参数重启有效 #include #include HINSTANCE hMainIns
    
    

    紧跟《注册表中RegSetValueEx用法》文章,自己写了一个测试程序,用到的注册表函数有:

    RegCreateKeyEx、RegSetValueEx、RegFlushKey、RegCloseKey。

       测试程序的功能是,谁知当前WINCE设备的IP地址,包括:子网掩码、默认网关等,并且使设置参数重启有效

    #include <ntddndis.h>
    #include <Iphlpapi.h>

    HINSTANCE hMainInstance=NULL;

    TCHAR szMsg[256];

    void Rebind_Adapter()
    {
        HANDLE hDevice;
        hDevice = CreateFile(
            TEXT("NDS0:"),
            GENERIC_READ | GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            NULL,
            OPEN_EXISTING,
            0,
            NULL);
        if (hDevice != INVALID_HANDLE_VALUE)
        {
            if(DeviceIoControl(
                           hDevice,
                           IOCTL_NDIS_REBIND_ADAPTER,
                           TEXT("CS89501/0"),
                           sizeof(TEXT("CS89501/0")),
                           NULL, 0, NULL, NULL))
      {
       RETAILMSG(1, (TEXT("Rebind NDS0 ok/r/n")));
      }
      else
      {
       RETAILMSG(1, (TEXT("Rebind NDS0 failed/r/n")));
      }

            CloseHandle(hDevice);
        }
        else
        {
      RETAILMSG(1, (TEXT("CreateFile NDS0 Failed/r/n")));
        }
    }

    void RegSetUStringValue(HKEY root, LPCWSTR Path, LPCWSTR Attr, LPCWSTR Value)
    {
     HKEY hKey;
     DWORD nDisposition;
     if (RegCreateKeyEx (root, Path, 0, NULL, 0, 0, 0, &hKey, &nDisposition) == ERROR_SUCCESS )
     {
      RegSetValueEx(hKey, Attr, 0, REG_SZ, (BYTE*)Value, wcslen(Value)*2);
      RETAILMSG(1, (TEXT("RegSetValueEx %s %d/r/n"), Value, wcslen(Value)));
      RegFlushKey(hKey);
      RegCloseKey(hKey);
     }
    }
    void RegSetUintValue(HKEY  root, LPCWSTR Path, LPCWSTR Attr, DWORD Value)
    {
     HKEY hKey;
     DWORD nDisposition;
     if (RegCreateKeyEx (root, Path, 0, NULL, 0, 0, 0, &hKey, &nDisposition) == ERROR_SUCCESS )
     {
            RegSetValueEx(hKey, Attr, 0, REG_DWORD, (BYTE*)(&Value), sizeof(DWORD));
            RegFlushKey(hKey);
      RegCloseKey(hKey);
     }
    }

    static void SetDHCP(HWND m_hWnd)
    {
        RegSetUintValue(HKEY_LOCAL_MACHINE, L"Comm//CS89501//Parms//TcpIp", L"EnableDHCP", 1);
        Rebind_Adapter();
    }

    static void SetStaticIP(HWND m_hWnd)
    {
     TCHAR szIpAddress[32];
     TCHAR szGateway[32];
     TCHAR szNetmask[32];

     memset(szIpAddress,0,sizeof(szIpAddress));
     GetWindowText(GetDlgItem(m_hWnd, IDC_EDIT_IPADDRESS), szIpAddress, sizeof(szIpAddress));
     memset(szGateway,0,sizeof(szGateway));
     GetWindowText(GetDlgItem(m_hWnd, IDC_EDIT_GATEWAY), szGateway, sizeof(szGateway));
     memset(szNetmask,0,sizeof(szNetmask));
     GetWindowText(GetDlgItem(m_hWnd, IDC_EDIT_NETMASK), szNetmask, sizeof(szNetmask));

     RETAILMSG(1, (TEXT("SetStaticIP/r/nszIpAddress = %s/r/n"), szIpAddress));
     RETAILMSG(1, (TEXT("szGateway = %s/r/n"), szGateway));
     RETAILMSG(1, (TEXT("szNetmask = %s/r/n"), szNetmask));

        RegSetUStringValue(HKEY_LOCAL_MACHINE, L"Comm//CS89501//Parms//TcpIp", L"IpAddress", szIpAddress);
        RegSetUStringValue(HKEY_LOCAL_MACHINE, L"Comm//CS89501//Parms//TcpIp", L"Subnetmask", szNetmask);
        RegSetUStringValue(HKEY_LOCAL_MACHINE, L"Comm//CS89501//Parms//TcpIp", L"DefaultGateway", szGateway);
        RegSetUintValue(HKEY_LOCAL_MACHINE, L"Comm//CS89501//Parms//TcpIp", L"EnableDHCP", 0);
        Rebind_Adapter();

    }

    void GetConfig(HWND m_hWnd)
    {
     int ret;
        IP_ADAPTER_INFO* pAdapterInfo = NULL;
        DWORD pOutBufLen = 0;
     TCHAR szIpAddress[32];
     TCHAR szGateway[32];
     TCHAR szNetmask[32];
     TCHAR szMacAddress[32];

        HKEY    hKey;
        DWORD  dwType;
        DWORD  dwCbData;
        DWORD   dwValue[3];
        
        ret = GetAdaptersInfo(pAdapterInfo, &pOutBufLen);
        
        pAdapterInfo = (IP_ADAPTER_INFO*)malloc(pOutBufLen);
        ret = GetAdaptersInfo(pAdapterInfo, &pOutBufLen);

     memset(szIpAddress,0,sizeof(szIpAddress));
     MultiByteToWideChar (CP_ACP, 0, pAdapterInfo->IpAddressList.IpAddress.String, strlen(pAdapterInfo->IpAddressList.IpAddress.String), szIpAddress, sizeof(szIpAddress));
     memset(szNetmask,0,sizeof(szNetmask));
     MultiByteToWideChar (CP_ACP, 0, pAdapterInfo->IpAddressList.IpMask.String, strlen(pAdapterInfo->IpAddressList.IpMask.String), szNetmask, sizeof(szNetmask));
     memset(szGateway,0,sizeof(szGateway));
     MultiByteToWideChar (CP_ACP, 0, pAdapterInfo->GatewayList.IpAddress.String, strlen(pAdapterInfo->GatewayList.IpAddress.String), szGateway, sizeof(szGateway));
     
     RETAILMSG(1, (TEXT("szIpAddress = %s/r/n"), szIpAddress));
     RETAILMSG(1, (TEXT("szGateway = %s/r/n"), szGateway));
     RETAILMSG(1, (TEXT("szNetmask = %s/r/n"), szNetmask));
     SetWindowText(GetDlgItem(m_hWnd, IDC_EDIT_IPADDRESS), szIpAddress);
     SetWindowText(GetDlgItem(m_hWnd, IDC_EDIT_GATEWAY), szGateway);
     SetWindowText(GetDlgItem(m_hWnd, IDC_EDIT_NETMASK), szNetmask);

     

        if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"Comm//CS89501//Parms", 0, 0, &hKey) == ERROR_SUCCESS)
        {
         dwType = REG_DWORD;
         dwCbData = sizeof(DWORD);
      RegQueryValueEx(hKey, L"MACAddress1", 0, &dwType, (LPBYTE)&dwValue[0], &dwCbData);
      RegQueryValueEx(hKey, L"MACAddress2", 0, &dwType, (LPBYTE)&dwValue[1], &dwCbData);
      RegQueryValueEx(hKey, L"MACAddress3", 0, &dwType, (LPBYTE)&dwValue[2], &dwCbData);
         _stprintf(szMacAddress, TEXT("%02x:%02x:%02x:%02x:%02x:%02x"),
             dwValue[0]&0xFF, (dwValue[0]>>8)&0xFF,
             dwValue[1]&0xFF, (dwValue[1]>>8)&0xFF,
             dwValue[2]&0xFF, (dwValue[2]>>8)&0xFF);
      SetWindowText(GetDlgItem(m_hWnd, IDC_EDIT_MACADDRESS), szMacAddress);
      RegFlushKey(hKey);
         RegCloseKey( hKey);
        }

    }

    void SaveMAC(HWND m_hWnd)
    {
        HKEY    hKey;
     TCHAR szMacAddress[32];
        DWORD   dwValue[6] = {0};
        DWORD  dwMacValue;

     memset(szMacAddress,0,sizeof(szMacAddress));
     GetWindowText(GetDlgItem(m_hWnd, IDC_EDIT_MACADDRESS), szMacAddress, sizeof(szMacAddress));
     
     _stscanf(szMacAddress, TEXT("%02x:%02x:%02x:%02x:%02x:%02x"),
      &dwValue[0],&dwValue[1],&dwValue[2],
      &dwValue[3],&dwValue[4],&dwValue[5]);
      

        if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"Comm//CS89501//Parms", 0, 0, &hKey) == ERROR_SUCCESS)
        {
      dwMacValue = (dwValue[1]<<8) + dwValue[0];
      RegSetValueEx(hKey, L"MACAddress1", 0, REG_DWORD, (LPBYTE)&dwMacValue, sizeof(DWORD));
      dwMacValue = (dwValue[3]<<8) + dwValue[2];
      RegSetValueEx(hKey, L"MACAddress2", 0, REG_DWORD, (LPBYTE)&dwMacValue, sizeof(DWORD));
      dwMacValue = (dwValue[5]<<8) + dwValue[4];
      RegSetValueEx(hKey, L"MACAddress3", 0, REG_DWORD, (LPBYTE)&dwMacValue, sizeof(DWORD));
      RegFlushKey(hKey);
         RegCloseKey(hKey);
         _stprintf(szMsg, TEXT("Save MAC Address/r/n%02x:%02x:%02x:%02x:%02x:%02x/r/n/r/nNeed to restart device./r/n"),
              dwValue[0]&0xFF, (dwValue[1])&0xFF,
              dwValue[2]&0xFF, (dwValue[3])&0xFF,
              dwValue[4]&0xFF, (dwValue[5])&0xFF);
     }
    }

     

    以下是相应设备原始注册表相关信息:

    [HKEY_LOCAL_MACHINE/Comm/CS8950]
       "DisplayName"="EP93xx Ethernet Driver"
       "Group"="NDIS"
       "ImagePath"="cs8950.dll"

    [HKEY_LOCAL_MACHINE/Comm/CS8950/Linkage]
       "Route"=multi_sz:"CS89501"

    [HKEY_LOCAL_MACHINE/Comm/CS89501]
       "DisplayName"="EP9312 Ethernet Driver"
       "Group"="NDIS"
       "ImagePath"="cs8950.dll"

    [HKEY_LOCAL_MACHINE/Comm/CS89501/Parms]
       "BusNumber"=dword:0
       "BusType"=dword:0
    ;   MACAddress: OverRide MAC Address stored in EEPROM.
    ;   The 1st (the least) DWord (32bits) of the MAC Address
       "MACAddress1"=dword:0012
    ;   The 2nd  DWord of the MAC Address
       "MACAddress2"=dword:3456
    ;   The 3rd (the most) DWord of the MAC Address
       "MACAddress3"=dword:7890

    ;   DuplexMode: 0:AutoNegotiate, 1:Half, 2:Full (Default:0)
       "DuplexMode"=dword:0
    ;   MediaSpeed: 0:AutoSense, 10:10_MBPS, 100:100_MBPS (Default:0)
       "MediaSpeed"=dword:0

    [HKEY_LOCAL_MACHINE/Comm/CS89501/Parms/TcpIp]
       "DefaultGateway"="192.168.0.1"
       "DontAddDefaultGateway"=dword:0
       "UseZeroBroadcast"=dword:0
       "IpAddress"="192.168.0.18"
       "Subnetmask"="255.255.255.0"
       "EnableDHCP"=dword:0

    [HKEY_LOCAL_MACHINE/Comm/Tcpip/Linkage]
       ; This should be MULTI_SZ
       ; This is the list of llip drivers to load
       "Bind"=multi_sz:"ppp","CS89501"

    展开全文
  • Wince修改IP地址而无需重启

    千次阅读 2013-05-17 15:37:58
    namespace Utitlity.Windows { using System; using System.Runtime.InteropServices; using Microsoft.Win32; /**//// /// 用于读取和配置以太网卡的IP地址信息 ... public static class IpHelper
    namespace Utitlity.Windows
    {
        using System;
        using System.Runtime.InteropServices;
        using Microsoft.Win32;
    
        /** <summary>
        /// 用于读取和配置以太网卡的IP地址信息
        /// </summary>
        public static class IpHelper
        {
            private const int OPEN_EXISTING = 3;
            private const int FILE_ATTRIBUTE_NORMAL = 0x80;
            private const int INVALID_HANDLE_VALUE = -1;
            private const int IOCTL_NDIS_REBIND_ADAPTER = 1507374;
            private const int IOCTL_NDIS_GET_ADAPTER_NAMES = 1507386;
    
            [DllImport("Coredll.dll", EntryPoint = "CreateFile")]
            private static extern int CreateFile(
                    string lpFileName,
                    int dwDesiredAccess,
                    int dwShareMode,
                    int lpSecurityAttributes,
                    int dwCreationDisposition,
                    int dwFlagsAndAttributes,
                    int hTemplateFile
                );
    
            [DllImport("Coredll.dll", EntryPoint = "DeviceIoControl")]
            private static extern int DeviceIoControl(
                    int hDevice,
                    int dwIoControlCode,
                    string lpInBuffer,
                    int nInBufferSize,
                    string lpOutBuffer,
                    int nOutBufferSize,
                    int lpBytesReturned,
                    int lpOverlapped
                );
    
            [DllImport("Coredll.dll", EntryPoint = "DeviceIoControl")]
            private static extern int DeviceIoControl2(
                    int hDevice,
                    int dwIoControlCode,
                    string lpInBuffer,
                    int nInBufferSize,
                    string lpOutBuffer,
                    int nOutBufferSize,
                    ref int lpBytesReturned,
                    int lpOverlapped
                );
    
            [DllImport("Coredll.dll", EntryPoint = "CloseHandle")]
            private static extern int CloseHandle(int hObject);
    
            /** <summary>
            /// 保存以太网卡IP地址信息的注册表节点
            /// </summary>
            private const string TcpIpRegKeyName = @"HKEY_LOCAL_MACHINE\Comm\{0}\Parms\TcpIp";
    
            /** <summary>
            /// IP地址注册表项名称
            /// </summary>
            private const string IpAddressItem = "IpAddress";
    
            /** <summary>
            /// 子网掩码的注册表项名称
            /// </summary>
            private const string SubnetMaskItem = "Subnetmask";
    
            /** <summary>
            /// 默认网关的注册表项名称
            /// </summary>
            private const string DefaultGatewayItem = "DefaultGageway";
    
            /** <summary>
            /// 以太网卡的设备文件名称
            /// </summary>
            private const string EtherCardFileName = "NDS0:";
    
            /** <summary>
            /// 以太网卡的名称
            /// </summary>
            private static string EtherCardName = string.Empty;
    
            /** <summary>
            /// 保存真实的以太网卡IP地址信息的注册表节点
            /// </summary>
            private static string RealTcpIpRegKeyName = string.Empty;
    
            /** <summary>
            /// 在注册表中对IP信息进行修改后,禁用网卡然后重启网卡以应用修改
            /// </summary>
            public static bool ApplyIpAddress()
            {
                int hNdis = CreateFile(EtherCardFileName, 0, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, INVALID_HANDLE_VALUE);
                if (hNdis == INVALID_HANDLE_VALUE)
                {
                    return false;
                }
    
                // Send the device command.
                if (DeviceIoControl(hNdis, IOCTL_NDIS_REBIND_ADAPTER, EtherCardName, EtherCardName.Length * 2 + 2, null, 0, 0, 0) == 0)
                {
                    return false;
                }
    
                CloseHandle(hNdis);
                return true;
            }
    
            /** <summary>
            /// 获取子网掩码
            /// </summary>
            /// <returns></returns>
            public static string GetSubnetMask()
            {
                return GetRegValue(SubnetMaskItem, "0.0.0.0");
            }
    
            /** <summary>
            /// 设置子网掩码
            /// </summary>
            /// <param name="subnetMask"></param>
            /// <returns></returns>
            public static bool SetSubnetMask(string subnetMask)
            {
                if (string.IsNullOrEmpty(subnetMask))
                {
                    throw new ArgumentNullException(subnetMask);
                }
    
                return SetRegValue(SubnetMaskItem, subnetMask);
            }
    
    
            /** <summary>
            /// 获取IP地址
            /// </summary>
            /// <returns></returns>
            public static string GetIpAddress()
            {
                return GetRegValue(IpAddressItem, "0.0.0.0");
            }
    
    
            /** <summary>
            /// 设置Ip地址
            /// </summary>
            /// <param name="ip"></param>
            public static bool SetIpAddress(string ip)
            {
                if (string.IsNullOrEmpty(ip))
                    throw new ArgumentNullException("ip");
    
                return SetRegValue(IpAddressItem, ip);
            }
    
    
    
            /** <summary>
            /// 获得网卡的名称
            /// </summary>
            /// <returns></returns>
            private static string GetEtherCardName()
            {
                string names = new string(' ', 255);
                int bytes = 0;
    
                int fileHandle = CreateFile(EtherCardFileName, 0, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, INVALID_HANDLE_VALUE);
                if (fileHandle == INVALID_HANDLE_VALUE)
                {
                    return string.Empty;
                }
    
                if (DeviceIoControl2(fileHandle, IOCTL_NDIS_GET_ADAPTER_NAMES, null, 0, names, 255, ref bytes, 0) == 0)
                {
                    return string.Empty;
                }
    
                int index = names.IndexOf('\0');
                string result = names.Substring(0, index);
                return result;
            }
    
    
            /** <summary>
            /// 获取注删表项的值
            /// </summary>
            private static string GetRegValue(string regItemName, string defaultValue)
            {
                if (string.IsNullOrEmpty(EtherCardName))
                {
                    EtherCardName = GetEtherCardName();
                    RealTcpIpRegKeyName = string.Format(TcpIpRegKeyName, EtherCardName);
                }
    
                if (!string.IsNullOrEmpty(EtherCardName))
                {
                    try
                    {
                        object value = Registry.GetValue(RealTcpIpRegKeyName, regItemName, defaultValue);
                        if(value!=null)
                        {
                            if(value.GetType() == typeof(string))
                            {
                                return (string) value;
                            }
                            if(value.GetType() == typeof(string[]))
                            {
                                return ((string[]) value)[0];
                            }
                        }
                    }
                    catch (Exception)
                    {
    
                    }
                }
                return defaultValue;
            }
    
            /** <summary>
            /// 设置注册表项的值
            /// </summary>
            private static bool SetRegValue(string regItemName, string value)
            {
                if (string.IsNullOrEmpty(EtherCardName))
                {
                    EtherCardName = GetEtherCardName();
                    RealTcpIpRegKeyName = string.Format(TcpIpRegKeyName, EtherCardName);
                }
                try
                {
                    Registry.SetValue(RealTcpIpRegKeyName, regItemName, value);
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
    
        }
    }
    

    使用方法如下:

     

    // IpHelper类的使用方法
    IpHelper.SetIpAddress("192.168.0.111");
    IpHelper.SetSubnetMask("192.168.0.111");
    IpHelper.ApplyIpAddress();
    // 通过修改IPHelper类,也可以实现修改某认网关的信息,因为我的项目不需要,所以未实现。
    


    展开全文
  • Wince中如何修改IP地址而无需重启。 最近做的一个项目中需要动态修改Wince5.0系统的IP地址,我们希望IP地址修改后可以立即生效而无需重启操作系统。经过一番Google.写出如下代码: IpHelpernamespaceUtitlity....
  • //Form1类后台#region 加载配置文件中的信息/// /// 加载配置文件中的信息/// protected void loadConfig(){cf.fileName = AppDomain.CurrentDomain...txtIP.Text = cf["ip地址"];txtSubMark.Text = cf["子网掩码"];...
  • 在应用程序中修改IP地址的方式: 1 ////////////////////////////////////////////////////////////////////////// 2 // Set IP Address, Mask and Gateway 3 // Through the registry entry: 4 // [...
  • WinCE冷启动自动修改IP

    千次阅读 2007-09-25 09:42:00
    include #include void main(){ CString m_strIp,m_strMask,m_strGateWay,m_strServerIP; DWORD m_dwServerPort = 0;... if ((fp = fopen("//Flash Disk//IP.txt","r")) == NULL)//读取存卡中的配置文件 { Mes
  • WINCEIP地址设置

    千次阅读 2010-11-03 15:13:00
    在注册表HKEY_LOCAL_MACHINE/Comm/SDIO86861/Parms/Tcpip/IpAddress里编辑添加多个IP即可配合静态路由表设置,可以实现路由规则的指定,以实现IP多路径...WINCE没有windows的route命令,需要自己编写修改路由表的工具。
  • WinCE6.0不重起修改IP地址

    千次阅读 2010-08-31 10:02:00
    ////////////////////...// Set IP Address, Mask and Gateway // Through the registry entry: // [HKEY_LOCAL_MACHINE/Comm/DM9CE1/Parms/TcpIp] // IpAddress, String // SubnetMask, String // Default
  • WinCE编译固定IP到内核

    2012-07-11 09:05:38
    因为自己建的CEPC调试环境中每次启动后都需要手动修改IP后才能调试网络程序,加入固定IP到内核中调试比较方便,具体方法如下: 修改工作区中的project.reg,添加以下内容: [HKEY_LOCAL_MACHINE\comm\vmini1\parms...
  • c++封装好的IP的获取和修改源码,通过NetworkCfg和wmi方式,支持Windows和WinCE系统,实际测试结果准确,使用简单
  • WinCE -- 编译固定IP到内核 修改工作区中的project.reg,添加以下内容: [HKEY_LOCAL_MACHINE/comm/DM9CE/parms/tcpip]  "defaultgateway" = multi_sz:"192.168.0.1"  "subnetmask" = multi_sz:"255.255....
  • 前几天一直很苦恼,找不到方法,恨不得把自己扔到大海里去。没想到,星星之火真可以燎原,因为一点小地方想明白了,接...2.ip的设定要修改网卡所在的注册表,这个sysgen可以,make run-time image也可以。3.开机自动运
  • wince 6.0下UDP通信需要注意MAC地址

    千次阅读 2015-02-04 22:10:04
    当然了,首先按照自己的使用配置wince中的IP修改注册表即可。  我是wince的菜鸟,但是绝不是使用UDP通信的新手,在windows下跑过多次的UDP发送端和接收端,在wince下却怎么都不能像在windows下使用那么顺利,出现...
  • wince 驱动文件与问答

    2010-08-19 23:30:00
    一、初级问答 1、wince驱动它以什么形式存在呢? dll 2、怎么把它加到wince内核中呢? platform.bib ...1、如何修改默认ip和网关呢? platform.reg 2、如何快速编译Wince系统呢? 命令行编译: "b
  • WinCE 6.0开发中,编译好NK.Bin文件后,通过一根网线直接与设备相连,网络显示局域网已连接,点击Target/Connectivity Options Target Device:CE Device ...还是要修改WinCE600文件夹下的哪个文件?
  • WinCE驱动开发问题精华集锦

    千次阅读 2010-05-07 18:08:00
    WinCE驱动开发问题精华集锦 收藏 1、在应用程序中,如何向修改本机的ip 地址等网络参数,并使之立即生效? 网络设置保存在注册表中,位置[HKEY_LOCAL_MACHINE/Com
  • TCP和MODBUS-TCP通讯调试软件V1.2_Wince_Winxp_通用版

    千次下载 热门讨论 2015-01-06 11:44:56
    修改一次最多读写寄存器个数120个。 4.增加WIN7等高版本系统支持。 5.欢迎交流,指正,本软件免费。 软件运行要求: 1.WINCE 系统上可以直接运行。 2.WINXP 系统上没装 VS2005 或更高版的 VS 软件的用户,可以到...
  • WinCE驱动开发问题精华集锦-1更多...http://hi.baidu.com/mcu_spaces1、在应用程序中,如何向修改本机的ip 地址等网络参数,并使之立即生效? 网络设置保存在注册表中,位置[HKEY_LOCAL_MACHINE/Comm/网卡名称/...
  • 1、在应用程序中,如何向修改本机的ip 地址等网络参数,并使之立即生效? 网络设置保存在注册表中,位置[HKEY_LOCAL_MACHINE\Comm\网卡名称\Parms\TcpIp],例如常见的CS8900网卡设置:[HKEY_LOCAL_MACHINE\Comm\CS...

空空如也

空空如也

1 2 3
收藏数 45
精华内容 18
关键字:

wince修改ip