PDA

View Full Version : سوال: ساخت کانکشن با DotRas



DeFeaT
سه شنبه 02 تیر 1394, 18:42 عصر
با سلام.
چطور میشه با استفاده از DotRas و باز کردن فایل pbk ( فکر کنم با pbk.open) نرم افزاری رو ساخت که فایل PBK رو باز کنه و با username و password که در Textbox ها نوشته شده ، به و| ، پ|، ن کانکشت شه؟

nimagame
پنج شنبه 04 تیر 1394, 02:00 صبح
دوستان منم در همین مورد مشکل دارم کسی بلد نیست؟

aliagamon
پنج شنبه 04 تیر 1394, 02:07 صبح
من یه کلاس یه مدت پیش تو نت پیدا کرده بودم یکم تغییرش دادم واسه کار خودم اینه کلاس کلا5-6 خطش عوض شده یکم option های کانکشنو عوض کردم میتونین خودتون تغییر بدین به نسبت کارتون اوکی میشه

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using DotRas;
using System.Text.RegularExpressions;
namespace Smart***
{
public class ***Manager
{
// The system path C:\windows\system32\
private static string WinDir = Environment.GetFolderPath(Environment.SpecialFolde r.System) + @"\";
// rasdial.exe
private static string RasDialFileName = "rasdial.exe";
// *** path C:\windows\system32\rasdial.exe
private static string ***PROCESS = WinDir + RasDialFileName;
// *** address
public string IPToPing { get; set; }
// The *** name
public string ***Name { get; set; }
// *** user name
public string UserName { get; set; }
// *** password
public string PassWord { get; set; }

public ***Manager()
{
}
/// <summary>
/// Parameterized constructor
/// </summary>
/// <param name="_***IP"></param>
/// <param name="_***Name"></param>
/// <param name="_userName"></param>
/// <param name="_passWord"></param>
public ***Manager(string _***IP, string _***Name, string _userName, string _passWord)
{
this.IPToPing = _***IP;
this.***Name = _***Name;
this.UserName = _userName;
this.PassWord = _passWord;
}
/// <summary>
/// Try to connect to the *** (default ***)
/// </summary>
/// <returns></returns>
public void TryConnect***()
{
this.TryConnect***(this.***Name, this.UserName, this.PassWord);
}
/// <summary>
/// Try to disconnect (default ***)
/// </summary>
/// <returns></returns>
public void TryDisConnect***()
{
this.TryDisConnect***(this.***Name);
}
/// <summary>
/// Create or update the connection a default ***
/// </summary>
public void CreateOrUpdate***()
{
this.CreateOrUpdate***(this.***Name, this.IPToPing);
}
/// <summary>
/// Try to delete the connection (default ***)
/// </summary>
/// <returns></returns>
public void TryDelete***()
{
this.TryDelete***(this.***Name);
}
/// <summary>
/// Try to connect to the *** (designated *** name, username, password)
/// </summary>
/// <returns></returns>
public void TryConnect***(string conn***Name, string connUserName, string connPassWord)
{
try
{

string args = string.Format(@"""{0}"" {1} {2}", conn***Name, connUserName, connPassWord);
ProcessStartInfo myProcess = new ProcessStartInfo(***PROCESS, args);
myProcess.CreateNoWindow = true;
myProcess.UseShellExecute = false;
Process.Start(myProcess);
}
catch (Exception Ex)
{
Debug.Assert(false, Ex.ToString());
}
}
/// <summary>
/// Try to disconnect *** (designated *** name)
/// </summary>
/// <returns></returns>
public void TryDisConnect***(string disConn***Name)
{
try
{
string args = string.Format(@"""{0}"" /d", disConn***Name);
ProcessStartInfo myProcess = new ProcessStartInfo(***PROCESS, args);
myProcess.CreateNoWindow = true;
myProcess.UseShellExecute = false;
Process.Start(myProcess);

}
catch (Exception Ex)
{
Debug.Assert(false, Ex.ToString());
}
}
/// <summary>
/// To create or update a connection to the *** (designated *** name, and IP)
/// </summary>
public void CreateOrUpdate***(string update***name, string update***ip)
{
RasDialer dialer = new RasDialer();
RasPhoneBook allUsersPhoneBook = new RasPhoneBook();
allUsersPhoneBook.Open();
// If you have the name *** already exists, then the update to the *** server address
if (allUsersPhoneBook.Entries.Contains(update***name) )
{
allUsersPhoneBook.Entries[update***name].PhoneNumber = update***ip;
// Regardless of whether the current *** connection, update always server address success, if you are connected, you need to restart *** to play
allUsersPhoneBook.Entries[update***name].Options.RequireEncryptedPassword = false;
allUsersPhoneBook.Entries[update***name].Update();
}
// Create a new ***
else
{
RasEntry entry = RasEntry.Create***Entry(update***name, update***ip, Ras***Strategy.PptpFirst, RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.***));
allUsersPhoneBook.Entries.Add(entry);
dialer.EntryName = update***name;
dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.All Users);
}
allUsersPhoneBook.Entries[update***name].EncryptionType = DotRas.RasEncryptionType.Optional;
allUsersPhoneBook.Entries[update***name].Options.RequireEncryptedPassword = false;
allUsersPhoneBook.Entries[update***name].Update();
}
/// <summary>
/// Delete the specified name ***
/// If *** is running, as will be deleted in the phone book, but not be disconnected, so, it is best to disconnect, then delete operation
/// </summary>
/// <param name="del***Name"></param>
public void TryDelete***(string del***Name)
{
RasDialer dialer = new RasDialer();
RasPhoneBook allUsersPhoneBook = new RasPhoneBook();
allUsersPhoneBook.Open();
if (allUsersPhoneBook.Entries.Contains(del***Name))
{
allUsersPhoneBook.Entries.Remove(del***Name);
}
}
/// <summary>
/// Gets the name of the *** is connected to the current
/// </summary>
public List<string> GetCurrentConnecting***Names()
{
List<string> Connecting***List = new List<string>();
Process proIP = new Process();
proIP.StartInfo.FileName = "cmd.exe ";
proIP.StartInfo.UseShellExecute = false;
proIP.StartInfo.RedirectStandardInput = true;
proIP.StartInfo.RedirectStandardOutput = true;
proIP.StartInfo.RedirectStandardError = true;
proIP.StartInfo.CreateNoWindow = true;//Don't show the CMD window
proIP.Start();
proIP.StandardInput.WriteLine(RasDialFileName);
proIP.StandardInput.WriteLine("exit");
// Command line operation results
string strResult = proIP.StandardOutput.ReadToEnd();
proIP.Close();
// Using the regular expression matching command line results, only the simplified Chinese system Oh^_^
Regex regger = new Regex("(?<=Successfully connected to \r\n) (.*\n) * (? = command completed)", RegexOptions.Multiline);
// If the match, that are connected to the ***
if (regger.IsMatch(strResult))
{
string[] list = regger.Match(strResult).Value.ToString().Split('\n ');
for (int index = 0; index < list.Length; index++)
{
if (list[index] != string.Empty)
Connecting***List.Add(list[index].Replace("\r", ""));
}
}
// There is no connection ***, directly returns an empty List<string>
return Connecting***List;
}
}
}

سایت autofilter داره هرجا *** دیدین خود سایت کلمه ی V/\P\/N رو فیلتر کرده هرجا دیدین *** هست این سه حرفو بزارین

nimagame
پنج شنبه 04 تیر 1394, 12:13 عصر
ممنون از راهنمایی ، اما این با استفاده از rasdial هست.

nimagame
شنبه 06 تیر 1394, 22:27 عصر
آقا کسی بلد نیست؟؟؟؟