• 0

[C#] Connect/disconnect from Internet


Question

7 answers to this question

Recommended Posts

  • 0

I have another problem - how can I enable/ disable a LAN connection? Suppose I have a LAN connection which keeps me connected and I want to disable it - how should I do it? And how can I enable it again?

I only know how to establish and cancel a dial up connection but how can I enable/ disable a LAN connection?

Can somebody please tell me?

  • 0

Does somebody know how can I get a list of all Internet connection the user has? I need to know the connections number and names in order to connect through InternetDial() so that's why I need it. Also - how can I get the current connected connection number? If I want to disconnect form the Internet I need to know the current connection number.

Edited by yyy
  • 0

Not sure wether it is in C++ or not, but unfortuinately, MS doesn't post examples and code using .NET languages in the Win API site :(

Therofre you need to convert it into your own language. I belive it's called p/invoke but I'm not sure.

Anyway, I'm not so good in this, but this time it was easy. Here it is in c#:

Decalre the dll files and the constants this way:

	[DllImport("wininet.dll")]
 ?private extern static bool InternetAutodial(int dwFlags, System.IntPtr hwndParent);
 ?[DllImport("wininet.dll")]
 ?private extern static bool InternetAutodialHangup(int dwReserved);

 Private Const INTERNET_AUTODIAL_FORCE_ONLINE = 1;

Now you can auto dial to the Internet ONLY if you set IE to auto dial to the Internet. If you want to dial a specific connection, or even when you don't set IE to auto dial, I'll tell you how. But it's more complicated.

Now you need to add this calls whenever you want to auto dial or auto disconnect:

InternetAutodial(INTERNET_AUTODIAL_FORCE_ONLINE , this.Handle);
InternetAutodialHangup(0);

I haven't tested this code yet, but I believe it will work. Tell me if you don't understand something, or if it doesn't work.

Hope that help:D :D

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

    • No registered users viewing this page.
  • Posts

    • Also, Guru3D.com always has some pros and experts lurking in the comments.
    • If anyone is wondering, it's 30fps at 4K
    • This 4K webcam from Acer is now only $59.99 by Taras Buria Those looking for an affordable, high-resolution webcam from a reputable manufacturer can check out the latest deal from Acer, which puts its 4K webcam at a solid price. Thanks to a 14% discount, you can buy this all-metal 4K webcam from Acer for just $59.99. Despite the affordable price tag, the webcam has a pretty large 1/2" CMOS sensor manufactured by Sony. Apart from its size, it supports additional conveniences, such as high dynamic range and phase-detection autofocus (PDAF). Plus, the camera ensures you do not have to buy additional audio equipment, as it comes with two built-in high-sensitivity microphones, a built-in background noise filter, and the ability to pick up your voice from up to 2.5 meters away. Acer is not cheaping out on materials, and the webcam is enclosed in a more premium metal case, which is also good at heat dissipation (high-resolution cameras can get quite hot). And to make sure no one is peeping at you when the camera is in use, there is a magnetic cover also made of metal. Additional conveniences include an LED status indicator and a built-in mount that lets you place a camera on a tripod. Acer 4K Webcam for PC/Mac with All-Metal Unibody Sculpted - $59.99 | 14% off Good to know This Amazon deal is U.S.-specific and not available in other regions unless specified. We only use first-party seller links (at the time of article publishing); ensure that you purchase from a first-party seller link only. Check out Today's Deals on Amazon | or our recent tech deals. Become a Prime member (for Students or SNAP) via Neowin Get Prime Access - Prime for half price (for qualifying Medicaid, EBT, SNAP) Subscribe to Prime Video, Audible Plus, Music Unlimited, or Kindle Unlimited via Neowin As an Amazon Associate, we earn from qualifying purchases.
  • Recent Achievements

    • Conversation Starter
      NovaEdgeX earned a badge
      Conversation Starter
    • One Year In
      Console General earned a badge
      One Year In
    • One Year In
      Twozo Technologies earned a badge
      One Year In
    • One Month Later
      Twozo Technologies earned a badge
      One Month Later
    • Week One Done
      Twozo Technologies earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      519
    2. 2
      +Edouard
      185
    3. 3
      PsYcHoKiLLa
      107
    4. 4
      Steven P.
      87
    5. 5
      ATLien_0
      67
  • Tell a friend

    Love Neowin? Tell a friend!