0

currently i am using wininet in my c# application to check internet connection it is working fine

[DllImport("wininet.dll", SetLastError = true)]
public extern static bool InternetGetConnectedState(out int lpdwFlags, int dwReserved);

    [Flags]
    public enum ConnectionStates
    {
        Modem = 0x1,
        LAN = 0x2,
        Proxy = 0x4,
        RasInstalled = 0x10,
        Offline = 0x20,
        Configured = 0x40,
    }

but the problem is i want to block internet but it is not successful how to achieve this using wininet?

Thanks in advance

  • 1
    You want to block the internet? Why? – Kirk Woll May 14 '13 at 16:17
  • @KirkWoll , with all respect , is that really important ? I guess question is something else !! – Mehran May 14 '13 at 16:19
  • @Mehran, it's important because I can think of no conceivable (legitimate) reason that a person would want to write a program that broke their user's internet. – Kirk Woll May 14 '13 at 16:20
  • 1
    i am just creating a parental control which can be schedule internet on some specific intervals only –  May 14 '13 at 16:20
  • http://stackoverflow.com/questions/8841991/how-to-disconnect-from-internet-using-c –  May 14 '13 at 16:24

1 Answers1

0

one way is using command prompt in your program :

if you use this command : rasdial /disconnect it will disconnect your current internet connection from internet

for executing this command in c# you can use this code :

            string command = "rasdial /disconnect";
            System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.UseShellExecute = false;
            procStartInfo.CreateNoWindow = true;
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = procStartInfo;
            proc.Start();

another solution from Windows API : RasHangUp function

Mehran
  • 1,409
  • 2
  • 17
  • 27
  • Internet connection is still there –  May 14 '13 at 17:30
  • execute `rasdial` on cmd , what's the output ? – Mehran May 14 '13 at 17:33
  • and still connected ? so I guess you should go with the API that mentioned above ! I'm not sure but I'm afraid that the API will do the same job as this command does ! – Mehran May 14 '13 at 17:35
  • yz still connected,is there any other way with wininet? –  May 14 '13 at 17:37
  • I'll look around , I if find any other solution , I'll let you know ;) – Mehran May 14 '13 at 17:38
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/29931/discussion-between-mad-and-mehran) –  May 14 '13 at 17:41