c# wince 禁止gprs/wcdma拨号时候弹出密码输入框

 有时候写程序需要直接把SIM卡用户名密码写入程序,这样方便省事,直接启动就行了,免得麻烦。

如下类,直接拨号前调用一下set()函数就可以了,已测试是OK的


public class wcdmaset
    {

        public static void set()
        {
            RASENTRY rasEntry = new RASENTRY();
            //RASDIALPARAMS RasDialParams = new RASDIALPARAMS(); ;
            int dwSize = Marshal.SizeOf(rasEntry);
            byte[] lpb = new byte[1024];
            int lpbSize = lpb.Length;
            int ret = -1;


            //初始化
            rasEntry.dwSize = dwSize;
            ret = RasGetEntryProperties(null, "WCDMA", ref rasEntry, ref dwSize, lpb, ref lpbSize);


            if (ret == 0)
            {
                rasEntry.dwfOptions &= ~RASEO_PreviewUserPw;
                ret = RasSetEntryProperties(null, "WCDMA", ref rasEntry, rasEntry.dwSize, 0, 0);
                //  ret = RasSetEntryProperties(null, entryName, ref rasEntry, rasEntry.dwSize, lpb, lpbSize);
            }


        }




        #region Ras.h Constants




        const int RAS_CHAR_SIZE = 2;
        const int MAX_PATH = 260;


        const int RAS_MaxEntryName = 20;
        const int RAS_MaxDeviceName = 128;
        const int RAS_MaxPhoneNumber = 128;
        const int RAS_MaxCallbackNumber = 48;


        const uint RASEO_PreviewUserPw = 0x01000000;
        /// <summary>
        /// Defines the maximum length of a device type.
        /// </summary>
        private const int RAS_MaxDeviceType = 16;


        /// <summary>
        /// Defines the maximum length of an IP address.
        /// </summary>
        private const int RAS_MaxIpAddress = 15;


        /// <summary>
        /// Defines the maximum length of an IPX address.
        /// </summary>
        private const int RAS_MaxIpxAddress = 21;




        /// <summary>
        /// Defines the maximum length of an area code.
        /// </summary>
        private const int RAS_MaxAreaCode = 10;


        /// <summary>
        /// Defines the maximum length of a pad type.
        /// </summary>
        private const int RAS_MaxPadType = 32;


        /// <summary>
        /// Defines the maximum length of an X25 address.
        /// </summary>
        private const int RAS_MaxX25Address = 200;


        /// <summary>
        /// Defines the maximum length of a facilities.
        /// </summary>
        private const int RAS_MaxFacilities = 200;


        /// <summary>
        /// Defines the maximum length of a user data.
        /// </summary>
        private const int RAS_MaxUserData = 200;


        /// <summary>
        /// Defines the maximum length of a reply message.
        /// </summary>
        private const int RAS_MaxReplyMessage = 1024;


        /// <summary>
        /// Defines the maximum length of a DNS suffix.
        /// </summary>
        private const int RAS_MaxDnsSuffix = 256;


        #endregion
        #region


        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct RASENTRY
        {
            public int dwSize;
            public uint dwfOptions;
            //
            // Location/phone number.
            //
            public int dwCountryID;
            public int dwCountryCode;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)RAS_MaxAreaCode + 1)]
            public string szAreaCode;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)RAS_MaxPhoneNumber + 1)]
            public string szLocalPhoneNumber;
            public int dwAlternateOffset;
            //
            // PPP/Ip
            //
            public RASIPADDR ipaddr;
            public RASIPADDR ipaddrDns;
            public RASIPADDR ipaddrDnsAlt;
            public RASIPADDR ipaddrWins;
            public RASIPADDR ipaddrWinsAlt;
            //
            // Framing
            //
            public int dwFrameSize;
            public int dwfNetProtocols;
            public int dwFramingProtocol;
            //
            // Scripting
            //
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)MAX_PATH)]
            public string szScript;
            //
            // AutoDial
            //
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)MAX_PATH)]
            public string szAutodialDll;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)MAX_PATH)]
            public string szAutodialFunc;
            //
            // Device
            //
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)RAS_MaxDeviceType + 1)]
            public string szDeviceType;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)RAS_MaxDeviceName + 1)]
            public string szDeviceName;
            //
            // X.25
            //
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)RAS_MaxPadType + 1)]
            public string szX25PadType;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)RAS_MaxX25Address + 1)]
            public string szX25Address;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)RAS_MaxFacilities + 1)]
            public string szX25Facilities;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)RAS_MaxUserData + 1)]
            public string szX25UserData;
            public int dwChannels;
            //
            // Reserved
            //
            public int dwReserved1;
            public int dwReserved2;
            public int dwCustomAuthKey;
        }


        /// <summary>
        /// Describes an IPv4 address.
        /// </summary>
        [StructLayout(LayoutKind.Sequential)]
        public struct RASIPADDR
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
            public byte[] addr;
        }




        /// <summary>
        /// Describes a remote access connection.
        /// </summary>
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct RASCONN
        {
            public int dwSize;
            public IntPtr hRasConnHandle;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxEntryName + 1)]
            public string entryName;
        }


        /// <summary>
        /// Describes a TAPI device capable of establishing a remote access service connection.
        /// </summary>
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct RASDEVINFO
        {
            public int size;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceType + 1)]
            public string type;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceName + 1)]
            public string name;
        }
        #endregion


        [DllImport("coredll.dll")]
        public static extern int RasGetEntryProperties(string lpszPhoneBook,
                                    string szEntry, ref RASENTRY lpEntry,
                                    ref int dwsize, byte[] lpb, ref int lpdwSize);


        /// <summary>
        /// Changes the connection information for an entry in the phone book or creates a new phone-book entry.
        /// </summary>
        /// <param name="lpszPhonebook">Pointer to a null-terminated string that specifies the full path and file name of a phone-book (PBK) file. 
        /// If this parameter is NULL, the function uses the current default phone-book file.</param>
        /// <param name="lpszEntry">Pointer to a null-terminated string that specifies an entry name. 
        /// If the entry name matches an existing entry, RasSetEntryProperties modifies the properties of that entry.
        /// If the entry name does not match an existing entry, RasSetEntryProperties creates a new phone-book entry.</param>
        /// <param name="lpRasEntry">Pointer to the RASENTRY structure that specifies the connection data to associate with the phone-book entry.</param>
        /// <param name="dwEntryInfoSize">Specifies the size, in bytes, of the buffer identified by the lpRasEntry parameter.</param>
        /// <param name="lpbDeviceInfo">This parameter is unused. The calling function should set this parameter to NULL.</param>
        /// <param name="dwDeviceInfoSize">This parameter is unused. The calling function should set this parameter to zero.</param>
        /// <returns></returns>
        [DllImport("Coredll.dll", SetLastError = true, CharSet = CharSet.Auto)]
        private static extern int RasSetEntryProperties(
                   string lpszPhonebook,
                   string lpszEntry,
                   ref RASENTRY lpRasEntry,
                   int dwEntryInfoSize,
                   byte lpb,//   byte[] lpb,
                   int dwDeviceInfoSize);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值