Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
rassetentryproperties (rasapi32)
The RasSetEntryProperties function changes the connection information for an entry in the phone book or creates a new phone-book entry.

C# Signature:

/// <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("rasapi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern Uint RasSetEntryProperties(
   string lpszPhonebook,
   string lpszEntry,
   ref RASENTRY lpRasEntry,
   int dwEntryInfoSize,
   IntPtr lpbDeviceInfo,
   int dwDeviceInfoSize);

VB Signature:

Declare Function RasSetEntryProperties Lib "rasapi32.dll" (TODO) As TODO

User-Defined Types:

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 4)]
    public struct RASENTRY
          public int       dwSize;
          public int       dwfOptions;
          public int       dwCountryID;
          public int       dwCountryCode;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) RasFieldSizeConstants.RAS_MaxAreaCode+1)]
          public string       szAreaCode;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) RasFieldSizeConstants.RAS_MaxPhoneNumber+1)]
          public string       szLocalPhoneNumber;
          public int       dwAlternateOffset;
          public RASIPADDR   ipaddr;
          public RASIPADDR   ipaddrDns;
          public RASIPADDR   ipaddrDnsAlt;
          public RASIPADDR   ipaddrWins;
          public RASIPADDR   ipaddrWinsAlt;
          public int       dwFrameSize;
          public int       dwfNetProtocols;
          public int       dwFramingProtocol;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) MAX_PATH)]
          public string       szScript;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) MAX_PATH)]
          public string       szAutodialDll;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) MAX_PATH)]
          public string       szAutodialFunc;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) RasFieldSizeConstants.RAS_MaxDeviceType + 1)]
          public string       szDeviceType;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) RasFieldSizeConstants.RAS_MaxDeviceName + 1)]
          public string       szDeviceName;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) RasFieldSizeConstants.RAS_MaxPadType + 1)]
          public string       szX25PadType;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) RasFieldSizeConstants.RAS_MaxX25Address + 1)]
          public string       szX25Address;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) RasFieldSizeConstants.RAS_MaxFacilities + 1)]
          public string       szX25Facilities;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) RasFieldSizeConstants.RAS_MaxUserData + 1)]
          public string       szX25UserData;
          public int       dwChannels;
          public int       dwReserved1;
          public int       dwReserved2;
          public int       dwSubEntries;
          public int       dwDialMode;
          public int       dwDialExtraPercent;
          public int       dwDialExtraSampleSeconds;
          public int       dwHangUpExtraPercent;
          public int       dwHangUpExtraSampleSeconds;
          public int       dwIdleDisconnectSeconds;
          public int       dwType;
          public int       dwEncryptionType;
          public int       dwCustomAuthKey;
          public Guid    guidId;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) MAX_PATH)]
          public string       szCustomDialDll;
          public int       dwVpnStrategy;
          public int       dwfOptions2;
          public int       dwfOptions3;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) RasFieldSizeConstants.RAS_MaxDnsSuffix)]
          public string       szDnsSuffix;
          public int       dwTcpWindowSize;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) MAX_PATH)]
          public string       szPrerequisitePbk;
          [MarshalAs(UnmanagedType.ByValTStr,SizeConst =
            (int) RasFieldSizeConstants.RAS_MaxEntryName)]
          public string       szPrerequisiteEntry;
          public int       dwRedialCount;
          public int       dwRedialPause;
          RASIPV6ADDR ipv6addrDns;
          RASIPV6ADDR ipv6addrDnsAlt;
          public int       dwIPv4InterfaceMetric;
          public int       dwIPv6InterfaceMetric;
          RASIPV6ADDR ipv6addr;
          public int       dwIPv6PrefixLength;
          public int       dwNetworkOutageTime;

    public struct RASIPADDR {
        byte a;
        byte b;
        byte c;
        byte d;

    public struct RASIPV6ADDR
        byte a;
        byte b;
        byte c;
        byte d;
        byte e;
        byte f;

    public enum RasEntryOptions
        RASEO_UseCountrAndAreaCodes = 0x00000001,
        RASEO_SpecificIpAddr = 0x00000002,
        RASEO_SpecificNameServers = 0x00000004,
        RASEO_IpHeaderCompression = 0x00000008,
        RASEO_RemoteDefaultGateway = 0x00000010,
        RASEO_DisableLcpExtensions = 0x00000020,
        RASEO_TerminalBeforeDial = 0x00000040,
        RASEO_TerminalAfterDial = 0x00000080,
        RASEO_ModemLights = 0x00000100,
        RASEO_SwCompression = 0x00000200,
        RASEO_RequireEncrptedPw = 0x00000400,
        RASEO_RequireMsEncrptedPw = 0x00000800,
        RASEO_RequireDataEncrption = 0x00001000,
        RASEO_NetworkLogon = 0x00002000,
        RASEO_UseLogonCredentials = 0x00004000,
        RASEO_PromoteAlternates = 0x00008000,
        RASEO_SecureLocalFiles = 0x00010000,
        RASEO_RequireEAP = 0x00020000,
        RASEO_RequirePAP = 0x00040000,
        RASEO_RequireSPAP = 0x00080000,
        RASEO_Custom = 0x00100000,
        RASEO_PreviewPhoneNumber = 0x00200000,
        RASEO_SharedPhoneNumbers = 0x00800000,
        RASEO_PreviewUserPw = 0x01000000,
        RASEO_PreviewDomain = 0x02000000,
        RASEO_ShowDialingProgress = 0x04000000,
        RASEO_RequireCHAP = 0x08000000,
        RASEO_RequireMsCHAP = 0x10000000,
        RASEO_RequireMsCHAP2 = 0x20000000,
        RASEO_RequireW95MSCHAP = 0x40000000


    public enum RasEntryOptions2
        None = 0x0,
        SecureFileAndPrint = 0x1,
        SecureClientForMSNet = 0x2,
        DoNotNegotiateMultilink = 0x4,
        DoNotUseRasCredentials = 0x8,
        UsePreSharedKey = 0x10,
        Internet = 0x20,
        DisableNbtOverIP = 0x40,
        UseGlobalDeviceSettings = 0x80,
        ReconnectIfDropped = 0x100,
        SharePhoneNumbers = 0x200,
        SecureRoutingCompartment = 0x400,
        UseTypicalSettings = 0x800,
        IPv6SpecificNameServer = 0x1000,
        IPv6RemoteDefaultGateway = 0x2000,
        RegisterIPWithDns = 0x4000,
        UseDnsSuffixForRegistration = 0x8000,
        IPv4ExplicitMetric = 0x10000,
        IPv6ExplicitMetric = 0x20000,
        DisableIkeNameEkuCheck = 0x40000,
        DisableClassBasedStaticRoute = 0x80000,
        IPv6SpecificAddress = 0x100000,
        DisableMobility = 0x200000,
        RequireMachineCertificates = 0x400000


    public enum RasEntryTypes
        RASET_Phone = 1,
        RASET_Vpn = 2,
        RASET_Direct = 3,
        RASET_Internet = 4

    public enum RasEntryEncryption
        ET_None      =   0,
        ET_Require    =  1,
        ET_RequireMax  = 2,
        ET_Optional    = 3

    public enum RasNetProtocols
        RASNP_NetBEUI = 0x00000001,
        RASNP_Ipx = 0x00000002,
        RASNP_Ip = 0x00000004,
        RASNP_Ipv6 = 0x00000008

    public enum RasFramingProtocol
        RASFP_Ppp = 0x00000001,
        RASFP_Slip = 0x00000002,
        RASFP_Ras = 0x00000004

Alternative Managed API:



Tips & Tricks:

Call RasGetEntryProperties beforehand, passing to it a null RASENTRY to get the correct buffer size (dwEntryInfoSize below).

    uint dwEntryInfoSize = 0;
    uint i = RasGetEntryProperties(null, "", IntPtr.Zero, ref dwEntryInfoSize, IntPtr.Zero, IntPtr.Zero);

Sample Code:

/// <summary>
/// Create or modify network connection.
/// </summary>
/// <param name="connectionName">Name of the network connection to create or modify.</param>
/// <param name="rasEntryStructure">RASENTRY structure containing connection settings.</param>
/// <returns>Enumerated RASERROR</returns>
public static RasError SetEntryProperties(string connectionName, RASENTRY rasEntryStructure)
     return (RasError)RasSetEntryProperties(null, connectionName, ref rasEntryStructure, Marshal.SizeOf(rasEntryStructure), IntPtr.Zero, 0);


Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version