• 0

[C#] Get the name of the current connection


Question

Recommended Posts

  • 0

Ok try this:

[Flags]
public enum InternetState
{
	INTERNET_CONNECTION_MODEM = 0x01,
	INTERNET_CONNECTION_LAN = 0x02,
	INTERNET_CONNECTION_PROXY = 0x04,
	INTERNET_CONNECTION_MODEM_BUSY = 0x08,
	INTERNET_RAS_INSTALLED = 0x10,
	INTERNET_CONNECTION_OFFLINE = 0x20,
	INTERNET_CONNECTION_CONFIGURED = 0x40
}

[DllImport("wininet.dll", CharSet=CharSet.Auto)]
public static extern bool InternetGetConnectedStateEx(out InternetState lpdwFlags, StringBuilder lpszConnectionName, int dwNameLen, int dwReserved);

............

InternetState connectionState;
StringBuilder connectionName = new StringBuilder(256);

bool isOnline = InternetGetConnectedStateEx(out connectionState, connectionName, 256, 0);

MessageBox.Show(isOnline.ToString());
MessageBox.Show(connectionState.ToString());
MessageBox.Show(connectionName.ToString());

Hopfully that will fix your problem :)

Dan

EDIT: Decided I may aswell add the InternetState enum for you :)

EDIT #2: Changed return type to boolean for the isOnline variable. :)

Edited by dannyres
Link to comment
Share on other sites

  • 0

:woot: :woot: :woot: :woot: :woot: :woot: :woot:

YESSSSSSSSSSSSSSSSS

:cool: :laugh: :) :rofl: :laugh: :cool: :jump: :fun:

It works (Y) I can't believe it - just as I wanted it.

You are so great dannyres (Y) I couldn't have done it without you. Sorry for bothering you and thank you very much. Thanks also to Andareed for trying to help :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.