在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → ADSL宽带拨号 (C#)实例源码下载

ADSL宽带拨号 (C#)实例源码下载

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.08M
  • 下载次数:38
  • 浏览次数:469
  • 发布时间:2014-07-16
  • 实例类别:C#语言基础
  • 发 布 人:shoujun
  • 文件格式:.rar
  • 所需积分:2
 相关标签: adsl拨号 adsl 拨号

实例介绍

实例截图:

部分源码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lqarpjj.Study.Demo.ADLSTool.Class;
using System.Diagnostics;
using System.IO;
using Microsoft.Win32;

namespace Lqarpjj.Study.Demo.ADLSTool
{
    public partial class frmMain : Form
    {
        #region 自定义变量
        /// <summary>
        /// 静态变量存储信息的地址文件
        /// </summary>
        private static string ADSLPath = Application.StartupPath   @"\ADSL.ini";

        private static string ConnectionsPath = Application.StartupPath   @"\create.vbs";
        /// <summary>
        /// 定义Ini写入对象
        /// </summary>
        private IniWrite ini = new IniWrite(ADSLPath);
        /// <summary>
        /// 判断第一登录
        /// </summary>
        private bool IsFirst = true;
        /// <summary>
        /// 
        /// </summary>
        private MD5.DES.Md5Class md5 = new MD5.DES.Md5Class();
        /// <summary>
        /// 
        /// </summary>
        public static string key = null;

        #endregion

        /// <summary>
        /// 构造函数
        /// </summary>
        public frmMain()
        {
            InitializeComponent();
        }

        #region 窗体事件
        /// <summary>
        /// 窗体初始
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmMain_Load(object sender, EventArgs e)
        {
            SetToolTip();
            IntiLoad(sender, e);
        }

        #endregion

        #region 控件按钮事件
        /// <summary>
        /// 复制账号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCopyAccount_Click(object sender, EventArgs e)
        {
            if (this.chkSpecial.Checked)//判断特殊拨号是否勾选
            {
                //进行加密
                UsernameEncode encode = new UsernameEncode();
                Clipboard.SetDataObject(encode.EncodeUsername(this.txtAccount.Text, this.txtPassword.Text));
            }
            else
            {
                Clipboard.SetDataObject(this.txtAccount.Text);
            }
            MessageBox.Show("账号已经复制到剪贴板!", "复制成功");
        }

        /// <summary>
        /// 拨号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDia_Click(object sender, EventArgs e)
        {
            if (this.txtAccount.Text.Trim() == "")
            {
                MessageBox.Show("账号不能为空", "输入错误");
                txtAccount.Focus();
                return;
            }
            if (this.txtPassword.Text.Trim() == "")
            {
                MessageBox.Show("密码不能为空", "输入错误");
                txtPassword.Focus();
                return;
            }
            this.NetDia();
        }

        /// <summary>
        /// 找不到电话簿?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lblNotFind_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.CreateConnections();
        }

        /// <summary>
        /// 记住账号联动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkRemAccount_CheckedChanged(object sender, EventArgs e)
        {
            if (!this.chkRemAccount.Checked)
            {
                this.chkRemPassword.Checked = false;
            }
        }

        /// <summary>
        /// 记住密码联动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkRemPassword_CheckedChanged(object sender, EventArgs e)
        {
            if (this.chkRemPassword.Checked)
            {
                this.chkRemAccount.Checked = true;
            }
        }

        /// <summary>
        /// 自动登录启动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AutoConectTimer_Tick(object sender, EventArgs e)
        {
            this.AutoConectTimer.Enabled = false;
            new frmLinkInfo(this).Show();
            base.Hide();
        }
        #endregion

        #region 自定义方法

        /// <summary>
        /// 初始登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void IntiLoad(object sender, EventArgs e)
        {
            FileInfo info = new FileInfo(ADSLPath);
            try
            {
                if (info.Exists)
                {
                    this.ReadConfig();
                }
                if (this.chkAutoDia.Checked)//是否自动登录
                {
                    this.AutoConectTimer.Start();
                }
            }
            catch (Exception)
            {
                File.Delete(ADSLPath);
                this.frmMain_Load(sender, e);
            }
        }

        /// <summary>
        ///设置控件提示
        /// </summary>
        private void SetToolTip()
        {
            ToolTip tip = new ToolTip();
            tip.BackColor = System.Drawing.Color.Transparent;
            tip.SetToolTip(this.btnCopyAccount, "复制账号到剪贴板。\n如果勾选了特殊拨号\n,复制的则是加密过\n的账号。");
            tip.SetToolTip(this.btnDia, "手动进行拨号。");
            tip.SetToolTip(this.chkAutoDia, "勾选后,下次启动将\n自动拨号。");
            tip.SetToolTip(this.chkSpecial, "如果你原本使用协同\n拨号器拨号,请勾选\n此项。");
            tip.SetToolTip(this.chkRemPassword, "勾选后,将会保存密\n码信息,同时保存账\n号信息。");
            tip.SetToolTip(this.chkRemAccount, "勾选后,将会保存账\n号信息,但不会保存\n密码信息。");
            tip.SetToolTip(this.txtPassword, "在这里输入你的密码\n。如果有字母,有大\n小写之分。");
            tip.SetToolTip(this.lblNotFind, "如果拨号时提示找不\n到电话簿,请点击这\n里。");
            tip.SetToolTip(this.txtAccount, "在这里输入你的用户\n名,如果是特殊拨号\n不分大小写。");
            tip.SetToolTip(this.chkAutoClo, "勾选后拨号成功将自\n动关闭程序,如果拨\n号失败,则不会自动\n关闭。");
        }

        /// <summary>
        /// 写入配置信息
        /// </summary>
        private void WriteConfig()
        {
            this.ini.Writue("用户设置", "记住账号", this.chkRemAccount.Checked.ToString());
            this.ini.Writue("用户设置", "记住密码", this.chkRemPassword.Checked.ToString());
            this.ini.Writue("用户设置", "特殊拨号", this.chkSpecial.Checked.ToString());
            this.ini.Writue("用户设置", "自动连接", this.chkAutoDia.Checked.ToString());
            this.ini.Writue("用户设置", "自动关闭", this.chkAutoClo.Checked.ToString());
            this.ini.Writue("用户设置", "首次使用", this.IsFirst.ToString());
            if (this.chkRemAccount.Checked)
            {
                this.ini.Writue("用户信息", "账号", this.md5.Encryption(this.txtAccount.Text));
                this.ini.Writue("加密密钥", "账号", key);
            }
            if (this.chkRemPassword.Checked)
            {
                this.ini.Writue("用户信息", "密码", this.md5.Encryption(this.txtPassword.Text));
                this.ini.Writue("加密密钥", "密码", key);
            }
        }

        /// <summary>
        /// 读取配置信息
        /// </summary>
        private void ReadConfig()
        {
            this.chkRemAccount.Checked = bool.Parse(this.ini.ReadValue("用户设置", "记住账号"));
            this.chkRemPassword.Checked = bool.Parse(this.ini.ReadValue("用户设置", "记住密码"));
            this.chkSpecial.Checked = bool.Parse(this.ini.ReadValue("用户设置", "特殊拨号"));
            this.chkAutoDia.Checked = bool.Parse(this.ini.ReadValue("用户设置", "自动连接"));
            this.chkAutoClo.Checked = bool.Parse(this.ini.ReadValue("用户设置", "自动关闭"));
            this.IsFirst = bool.Parse(this.ini.ReadValue("用户设置", "首次使用"));
            if (this.chkRemAccount.Checked)
            {
                this.txtAccount.Text = this.md5.Decryption(this.ini.ReadValue("加密密钥", "账号"), this.ini.ReadValue("用户信息", "账号"));
                if (this.txtAccount.Text.Trim() == "")
                {
                    this.txtAccount.Text = null;
                }
            }
            if (this.chkRemPassword.Checked)
            {
                this.txtPassword.Text = this.md5.Decryption(this.ini.ReadValue("加密密钥", "密码"), this.ini.ReadValue("用户信息", "密码"));
                if (this.txtPassword.Text.Trim() == "")
                {
                    this.txtPassword.Text = null;
                }
            }
        }

        /// <summary>
        /// 判断是否是第一次使用本软件
        /// </summary>
        private void IsFirstUse()
        {
            if (this.IsFirst)
            {
                if (MessageBox.Show("检测到您是初次使用本软\n件,是否自动创建一个名\n为【宽带连接】的连接?\n如果已经存在,请选否。", "初次使用", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.CreateConnections();
                }
                this.IsFirst = false;
                this.WriteConfig();
            }
        }

        /// <summary>
        /// 连接宽带
        /// </summary>
        private void NetDia()
        {
            this.IsFirstUse();
            new frmLinkInfo(this).Show();
            base.Hide();
        }

        /// <summary>
        /// 电话簿
        /// </summary>
        private void CreateConnections()
        {
            Process[] processArray;
            StreamWriter writer = new StreamWriter(ConnectionsPath, false, Encoding.Default);
            writer.Write(this.GetVersion());
            writer.Close();
            Process process = new Process();
            process.StartInfo.FileName = ConnectionsPath;
            process.StartInfo.CreateNoWindow = true;
            base.Hide();
            process.Start();
            process.WaitForExit();
            File.Delete(ConnectionsPath);
        Label_006A:
            processArray = Process.GetProcesses();
            foreach (Process process2 in processArray)
            {
                if (process2.ProcessName.ToString() == "rasphone")
                {
                    goto Label_006A;
                }
            }
            base.Show();
        }

        /// <summary>
        /// 获取版本?
        /// </summary>
        /// <returns></returns>
        private string GetVersion()
        {
            StringBuilder str = new StringBuilder();
            str.Append("\r\n");
            str.Append("set ws=createobject(\"wscript.shell\")\r\n ");
            str.Append("    ws.run \"rasphone -a 宽带连接\"\r\n  ");
            str.Append("    wscript.sleep 200\r\n ");
            str.Append("        ws.sendkeys \"{t}\"\r\n ");
            str.Append("    wscript.sleep 200\r\n  ");
            str.Append("        ws.sendkeys \"{n}\"\r\n ");
            str.Append("    wscript.sleep 200\r\n  ");
            str.Append("        ws.sendkeys \"{enter}\"\r\n  ");
            str.Append("    wscript.sleep 200\r\n ");
            str.Append("        ws.sendkeys \"{enter}\"\r\n ");
            if (Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion").GetValue("ProductName").ToString() == "Windows 7 Ultimate")
            {
                str.Append("\r\n");
                str.Append("set ws=createobject(\"wscript.shell\")\r\n");
                str.Append("    ws.run \"rasphone -a 宽带连接\"\r\n");
                str.Append("    wscript.sleep 200\r\n");
                str.Append("        ws.sendkeys \"{enter}\"\r\n");
                str.Append("    wscript.sleep 200\r\n");
                str.Append("        ws.sendkeys \"{enter}\"\r\n");
            }
            return str.ToString();
        }

        #endregion
    }
}

标签: adsl拨号 adsl 拨号

实例下载地址

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警