public IEnumerable <string> GetProfiles() { int cb = Marshal.SizeOf(typeof(RASENTRYNAME)), entries = 0; var entryNames = new RASENTRYNAME[1]; entryNames[0].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME)); var nRet = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, entryNames, ref cb, ref entries); if (entries == 0) { yield break; } entryNames = new RASENTRYNAME[entries]; for (var i = 0; i < entries; i++) { entryNames[i].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME)); } nRet = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, entryNames, ref cb, ref entries); for (var i = 0; i < entries; i++) { yield return(entryNames[i].szEntryName); } }
public static RASENTRYNAME[] GetConnections() { int cb = Marshal.SizeOf(typeof(RASENTRYNAME)), entries = 0; RASENTRYNAME[] entryNames = new RASENTRYNAME[1]; entryNames[0].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME)); //Get entry number uint nRet = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, entryNames, ref cb, ref entries); if (entries == 0) { return(new RASENTRYNAME[0]); } string[] _EntryNames = new string[entries]; entryNames = new RASENTRYNAME[entries]; for (int i = 0; i < entries; i++) { entryNames[i].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME)); } nRet = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, entryNames, ref cb, ref entries); if (nRet != (int)winerror.ERROR_SUCCESS) { throw new Exception("RasEnumEntries" + nRet.ToString()); } return(entryNames); }
internal static string[] GetConnectionNames() { if (CONFIG.bDebugSpew) { FiddlerApplication.DebugSpew("WinINET indicates connectivity is via: " + GetConnectedState()); } try { RASENTRYNAME[] rasentrynameArray; uint num3; int lpcb = Marshal.SizeOf(typeof(RASENTRYNAME)); int lpcEntries = 0; if (Environment.OSVersion.Version.Major < 6) { rasentrynameArray = new RASENTRYNAME[1]; rasentrynameArray[0].dwSize = lpcb; num3 = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, rasentrynameArray, ref lpcb, ref lpcEntries); } else { num3 = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, ref lpcb, ref lpcEntries); } if ((num3 != 0) && (0x25b != num3)) { FiddlerApplication.Log.LogFormat("! WARNING: RasEnumEntries failed (0x{0:x}). Ignoring non-LAN Connectoids. ", new object[] { num3 }); lpcEntries = 0; } string[] strArray = new string[lpcEntries + 1]; strArray[0] = "DefaultLAN"; if (lpcEntries != 0) { rasentrynameArray = new RASENTRYNAME[lpcEntries]; for (int i = 0; i < lpcEntries; i++) { rasentrynameArray[i].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME)); } num3 = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, rasentrynameArray, ref lpcb, ref lpcEntries); if (num3 != 0) { FiddlerApplication.Log.LogFormat("! WARNING: RasEnumEntries failed (0x{0:x}). Ignoring non-LAN Connectoids. ", new object[] { num3 }); return new string[] { "DefaultLAN" }; } for (int j = 0; j < lpcEntries; j++) { strArray[j + 1] = rasentrynameArray[j].szEntryName; } } return strArray; } catch (Exception exception) { FiddlerApplication.Log.LogFormat("! WARNING: Enumerating connections failed. Ignoring non-LAN Connectoids.\n{0}", new object[] { Utilities.DescribeException(exception) }); return new string[] { "DefaultLAN" }; } }
public bool GetEntries(out string[] strEntryName, out string strError) { strError = ""; RASENTRYNAME[] lprasentryname = new RASENTRYNAME[1]; lprasentryname[0].dwSize = Marshal.SizeOf(lprasentryname[0]); int lpcb = 0; int lpcEntries = 0; int nErrorValue = RasEnumEntries(null, null, lprasentryname, ref lpcb, ref lpcEntries); switch (nErrorValue) { case 0: break; case 0x25b: lprasentryname = new RASENTRYNAME[lpcEntries]; lprasentryname[0].dwSize = Marshal.SizeOf(lprasentryname[0]); break; default: //strError = this.GetErrorString(nErrorValue); strEntryName = null; return(false); } nErrorValue = RasEnumEntries(null, null, lprasentryname, ref lpcb, ref lpcEntries); if (nErrorValue != 0) { //strError = this.GetErrorString(nErrorValue); strEntryName = null; return(false); } strEntryName = new string[lpcEntries]; for (int i = 0; i < lpcEntries; i++) { strEntryName[i] = lprasentryname[i].szEntryName; } strError = null; return(true); }
internal static string[] GetConnectionNames() { if (Browser.bDebugSpew) { SDVPApplication.DebugSpew("WinINET indicates connectivity is via: " + GetConnectedState()); } int lpcb = Marshal.SizeOf(typeof(RASENTRYNAME)); int lpcEntries = 0; RASENTRYNAME[] lprasentryname = new RASENTRYNAME[1]; lprasentryname[0].dwSize = lpcb; uint num3 = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, lprasentryname, ref lpcb, ref lpcEntries); if ((num3 != 0) && (0x25b != num3)) { lpcEntries = 0; } string[] strArray = new string[lpcEntries + 1]; strArray[0] = "DefaultLAN"; if (lpcEntries != 0) { lprasentryname = new RASENTRYNAME[lpcEntries]; for (int i = 0; i < lpcEntries; i++) { lprasentryname[i].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME)); } if (RasEnumEntries(IntPtr.Zero, IntPtr.Zero, lprasentryname, ref lpcb, ref lpcEntries) != 0) { return(strArray); } for (int j = 0; j < lpcEntries; j++) { strArray[j + 1] = lprasentryname[j].szEntryName; } } return(strArray); }
/// <summary> /// 得到条目 /// </summary> /// <param name="strEntryName">条目名称</param> /// <param name="strError">错误</param> /// <returns>结果</returns> public bool GetEntries(out string[] strEntryName, out string strError) { RASENTRYNAME[] lprasentryname = new RASENTRYNAME[1]; lprasentryname[0].dwSize = Marshal.SizeOf(lprasentryname[0]); int lpcb = 0; int lpcEntries = 0; int nErrorValue = RasEnumEntries(null, null, lprasentryname, ref lpcb, ref lpcEntries); switch (nErrorValue) { case 0: break; case 0x25b: lprasentryname = new RASENTRYNAME[lpcEntries]; lprasentryname[0].dwSize = Marshal.SizeOf(lprasentryname[0]); break; default: strError = this.GetErrorString(nErrorValue); strEntryName = null; return false; } nErrorValue = RasEnumEntries(null, null, lprasentryname, ref lpcb, ref lpcEntries); if (nErrorValue != 0) { strError = this.GetErrorString(nErrorValue); strEntryName = null; return false; } strEntryName = new string[lpcEntries]; for (int i = 0; i < lpcEntries; i++) { strEntryName[i] = lprasentryname[i].szEntryName; } strError = null; return true; }