/// <summary>
        /// Creates a dial-up connection in the windows list of connections.
        /// </summary>
        /// <param name="dialupConnectionName">The name of the dial-up connection to create.</param>
        /// <param name="phoneNumber">The phone number to be dialed when dialing the dial-up connection.</param>
        /// <param name="deviceType">The RAS (Remote Access Serice) device type. If null the default is used i.e.RasDeviceType.Modem</param>
        /// <param name="deviceName">The name of the RAS device. May not be null.</param>
        public void CreateDialupConnectionEntry(
            string dialupConnectionName,
            string phoneNumber,
            Nullable <RasDeviceType> deviceType,
            string deviceName)
        {
            _rasPhoneBook.Open();
            if (string.IsNullOrEmpty(dialupConnectionName))
            {
                throw new NullReferenceException("dialupConnectionName may not be null or empty when requesting for a dial-up connection to be created.");
            }
            if (string.IsNullOrEmpty(phoneNumber))
            {
                throw new NullReferenceException("phoneNumber may not be null or empty when requesting to for dial-up connection to be created.");
            }
            if (!deviceType.HasValue)
            {
                deviceType = RasDeviceType.Modem;
            }
            RasEntry entry = RasEntry.CreateDialUpEntry(
                dialupConnectionName,
                phoneNumber,
                RasDevice.GetDeviceByName(deviceName, deviceType.Value));

            _rasPhoneBook.Entries.Add(entry);
        }
示例#2
0
        public static void Dial(Contact contact)
        {
            RasPhoneBook phoneBook = new RasPhoneBook();

            phoneBook.Open();

            if (!phoneBook.Entries.Contains(networkConnectionName))
            {
                DotRas.RasEntry entry = RasEntry.CreateDialUpEntry(networkConnectionName, contact.number, RasDevice.GetDeviceByName("Modem", RasDeviceType.Modem, false));
                phoneBook.Entries.Add(entry);
            }

            RasDialer dialer = new RasDialer();

            phoneBook.Entries[networkConnectionName].PhoneNumber = contact.number;
            phoneBook.Entries[networkConnectionName].Update();
            dialer.EntryName      = networkConnectionName;
            dialer.DialCompleted += new EventHandler <DialCompletedEventArgs>(Dialer.dialer_DialCompleted);
            dialer.StateChanged  += new EventHandler <StateChangedEventArgs>(Dialer.dialer_StateChanged);
            TargetDotRas.dialer   = dialer;

            dialer.DialAsync(new System.Net.NetworkCredential(networkCredentialUsername, networkCredentialPassword));
        }
示例#3
0
        //This creates the M5 phonebook with all the necessary parameters in it
        private static void CreateRas(string phonebookPath)
        {
            DotRas.RasPhoneBook pb = new DotRas.RasPhoneBook();
            pb.Open(phonebookPath);
            RasDevice rasDevice = RasDevice.GetDevices().Where(P => P.DeviceType == RasDeviceType.Modem && P.Name.ToUpper().StartsWith("M5-")).FirstOrDefault();

            if (rasDevice == null)
            {
                return;
            }

            RasEntry entry = pb.Entries.Where(p => p.Name == "M5_1").FirstOrDefault();

            if (entry == null)
            {
                entry = RasEntry.CreateDialUpEntry("M5_1", "0", rasDevice);
            }

            entry.FramingProtocol = RasFramingProtocol.Ppp;
            entry.EncryptionType  = RasEncryptionType.None;
            entry.FrameSize       = 0;

            entry.Options.DisableLcpExtensions    = true;
            entry.Options.DisableNbtOverIP        = true;
            entry.Options.DoNotNegotiateMultilink = true;
            entry.Options.DoNotUseRasCredentials  = true;
            entry.Options.Internet            = false;
            entry.Options.IPHeaderCompression = false;
            entry.Options.ModemLights         = true;
            entry.Options.NetworkLogOn        = false;

            entry.Options.PreviewDomain       = false;
            entry.Options.PreviewPhoneNumber  = false;
            entry.Options.PreviewUserPassword = false;
            entry.Options.PromoteAlternates   = false;

            entry.Options.ReconnectIfDropped   = false;
            entry.Options.RemoteDefaultGateway = false;

            entry.Options.RequireChap                = false;
            entry.Options.RequireDataEncryption      = false;
            entry.Options.RequireEap                 = false;
            entry.Options.RequireEncryptedPassword   = false;
            entry.Options.RequireMSChap              = false;
            entry.Options.RequireMSChap2             = false;
            entry.Options.RequireMSEncryptedPassword = false;
            entry.Options.RequirePap                 = false;
            entry.Options.RequireSpap                = false;
            entry.Options.RequireWin95MSChap         = false;

            entry.Options.SecureClientForMSNet = true;
            entry.Options.SecureFileAndPrint   = true;
            entry.Options.SecureLocalFiles     = true;

            entry.Options.SharedPhoneNumbers  = false;
            entry.Options.SharePhoneNumbers   = false;
            entry.Options.ShowDialingProgress = false;

            entry.Options.SoftwareCompression = false;
            entry.Options.TerminalAfterDial   = false;
            entry.Options.TerminalBeforeDial  = false;

            entry.Options.UseCountryAndAreaCodes  = false;
            entry.Options.UseGlobalDeviceSettings = false;
            entry.Options.UseLogOnCredentials     = false;
            entry.Options.UsePreSharedKey         = false;

            if (pb.Entries.Contains(entry.Name))
            {
                entry.Update();
            }
            else
            {
                pb.Entries.Add(entry);
            }
        }