Beispiel #1
0
 private void btn_CreateRAS_Click(object sender, EventArgs e)
 {
     try
     {
         Userinfo userinfo = new Userinfo(tb_user.Text, tb_pwd.Text);
         this.AllUsersPhoneBook.Open();
         RasEntry entry = RasEntry.CreateVpnEntry(EntryName, IP, RasVpnStrategy.L2tpOnly,
                                                  RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn));
         entry.Options.DoNotNegotiateMultilink = false;  //多链路
         entry.EncryptionType = RasEncryptionType.None;  //允许未加密密码
         entry.Options.RequireEncryptedPassword = false;
         entry.NetworkProtocols.IPv6            = false; //取消IPV6服务
         entry.Options.CacheCredentials         = true;  //win8以上记住密码
         DialogResult result = MessageBox.Show("你确定要创建账号为 " + userinfo.User + " 密码为 " + userinfo.Pwd + " 的拨号程序吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
         if (result == DialogResult.No)
         {
             return;
         }
         foreach (RasEntry temp in this.AllUsersPhoneBook.Entries)
         {
             if (temp.Name == entry.Name)
             {
                 MessageBox.Show("创建失败,已经存在拨号连接 " + entry.Name, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 return;
             }
         }
         this.status.Text = "创建中...";
         this.AllUsersPhoneBook.Entries.Add(entry);
         if (tb_user.Text != "" && tb_pwd.Text != "")
         {
             NetworkCredential credential = new NetworkCredential(tb_user.Text, tb_pwd.Text);
             entry.UpdateCredentials(credential);
         }
         MessageBox.Show("创建成功!请点击右下角网络连接处的 " + entry.Name + " \n为您添加路由ing...", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         btn_hzly_Click(this, new EventArgs());
         this.status.Text = "创建成功!";
     }
     catch
     {
         MessageBox.Show("创建失败,请设定防火墙允许!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         Process.GetCurrentProcess().Kill();
     }
 }
Beispiel #2
0
 private void btn_CreateRAS_Click(object sender, EventArgs e)
 {
     try
     {
         Userinfo userinfo = new Userinfo(tb_user.Text, tb_pwd.Text);
         this.AllUsersPhoneBook.Open();
         RasEntry entry = RasEntry.CreateVpnEntry(EntryName, IP, RasVpnStrategy.L2tpOnly,
             RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn));
         entry.Options.DoNotNegotiateMultilink = false;  //多链路
         entry.EncryptionType = RasEncryptionType.None;  //允许未加密密码
         entry.Options.RequireEncryptedPassword = false;
         entry.NetworkProtocols.IPv6 = false;  //取消IPV6服务
         entry.Options.CacheCredentials = true;  //win8以上记住密码
         DialogResult result = MessageBox.Show("你确定要创建账号为 " + userinfo.User + " 密码为 " + userinfo.Pwd + " 的拨号程序吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
         if (result == DialogResult.No)
             return;
         foreach (RasEntry temp in this.AllUsersPhoneBook.Entries)
             if (temp.Name == entry.Name)
             {
                 MessageBox.Show("创建失败,已经存在拨号连接 " + entry.Name, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 return;
             }
         this.status.Text = "创建中...";
         this.AllUsersPhoneBook.Entries.Add(entry);
         if (tb_user.Text != "" && tb_pwd.Text != "")
         {
             NetworkCredential credential = new NetworkCredential(tb_user.Text, tb_pwd.Text);
             entry.UpdateCredentials(credential);
         }
         MessageBox.Show("创建成功!请点击右下角网络连接处的 " + entry.Name + " \n为您添加路由ing...", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         btn_hzly_Click(this, new EventArgs());
         this.status.Text = "创建成功!";
     }
     catch
     {
         MessageBox.Show("创建失败,请设定防火墙允许!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         Process.GetCurrentProcess().Kill();
     }
 }