Click here to Skip to main content
15,891,906 members
Home / Discussions / C#
   

C#

 
GeneralRe: Web service timeout Pin
Chals2-Jun-05 1:31
Chals2-Jun-05 1:31 
GeneralWindow Proc Pin
Sabry19052-Jun-05 1:07
Sabry19052-Jun-05 1:07 
GeneralRe: Window Proc Pin
S. Senthil Kumar2-Jun-05 1:22
S. Senthil Kumar2-Jun-05 1:22 
GeneralC# and Outlook Navigation Pane. Pin
HakunaMatada2-Jun-05 0:17
HakunaMatada2-Jun-05 0:17 
GeneralOOP design pattern Pin
Jonas Beckeman (2)1-Jun-05 23:16
Jonas Beckeman (2)1-Jun-05 23:16 
GeneralRe: OOP design pattern Pin
Colin Angus Mackay2-Jun-05 1:09
Colin Angus Mackay2-Jun-05 1:09 
GeneralRe: OOP design pattern Pin
Jonas Beckeman (2)2-Jun-05 2:11
Jonas Beckeman (2)2-Jun-05 2:11 
GeneralChecking Modem and LAN Connection Pin
ksanju10001-Jun-05 21:24
ksanju10001-Jun-05 21:24 
Hi ,
This is code has been written in Vb.net
In Winform there are two button. First button checks for LAN connection nad Second button checks for Modem connection.
When i connects thr dial up and press modem connection then it works fine
but for LAN connection it does not work it traps the dial up connection and retruns the value FALSE
Note: I have connected thr LAN and dial up thr modem (Basically it connects two computer using modem)
This program perfectly works for Modem but it does not work for LAN
can somebody modifies this program
----------------------------------

Imports System.IO, Microsoft.Win32
Public Class Form1
Inherits System.Windows.Forms.Form
Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" _
(ByRef lpdwFlags As Long, _
ByVal lpszConnectionName As String, _
ByVal dwNameLen As Long, ByVal dwReserved As Long) As Boolean

Public Const ModemConnection As Integer = &H1S
Dim Status, Status1, DissNotWritten As Boolean
Public CntType As Long, CntName As String, CntNameLen As Long = 50
Public CntType1 As Long, CntName1 As String = Space(50), CntNameLen1 As Long = 50
Public Const LanConnection As Integer = &H2S

Public Function IsModemConnection() As Boolean
Dim dwflags As Integer

'return True if modem connection.
' MessageBox.Show(ModemConnection)
' MessageBox.Show(Status)
' MessageBox.Show(IsModemConnection)

Status = InternetGetConnectedStateEx(CntType, CntName, CntNameLen, 0)
IsModemConnection = CntType And ModemConnection And Status
'MessageBox.Show(IsModemConnection)
End Function

Public Function IsLanConnection() As Boolean
Dim dwflags As Integer
'return True if LAN connection
Status1 = InternetGetConnectedStateEx(CntType1, CntName1, CntNameLen1, 0)
IsLanConnection = CntType1 And LanConnection And Status1
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not IsModemConnection() Then
DissNotWritten = False

MessageBox.Show("Not Connected To Internet !!!")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Else

MessageBox.Show("Connected To Internet !!!")
End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Not IsLanConnection() Then
DissNotWritten = False
MessageBox.Show("Not Connected on LAN !!!")

Else
MessageBox.Show("Connected on LAN !!!")
End If
End Sub
This modemcheck program has been written in Vb.net which only checks for modem It does not check the separate LAN connection i need to checks for LAN also bec in my computer I have only Local area connection and one modem connection
This program i converted into C sharp
----------------------------------
In This C sharp program it does not check for MOdem connection i have used same thing what i used in VB.net above modem connectivity program

Can anyone modify it
I tested in vb.net its working for modem ocnnection but when i connect also LAN connection

modemcheckcsharp.cs
----------------------
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32;


[System.Runtime.InteropServices.DllImport("wininet.dll", EntryPoint="InternetGetConnectedStateExA", ExactSpelling=false, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
private static extern bool InternetGetConnectedStateEx(ref long lpdwFlags, string lpszConnectionName, long dwNameLen, long dwReserved);

public const int ModemConnection = 0X1;
private bool Status;
private bool Status1;
private bool DissNotWritten;
public long CntType;
public string CntName;
public long CntNameLen = 50;
public long CntType1;
public string CntName1 = string.Empty.PadLeft(50);
public long CntNameLen1 = 50;
public const int LanConnection = 0X2;

public bool IsModemConnection()
{
int dwflags = 0;

//return True if modem connection.
// MessageBox.Show(ModemConnection)
// MessageBox.Show(Status)
// MessageBox.Show(IsModemConnection)

Status = InternetGetConnectedStateEx(ref CntType, CntName, CntNameLen, 0);
return Convert.ToBoolean(CntType) & Convert.ToBoolean(ModemConnection) & Status;
//MessageBox.Show(IsModemConnection)
}

public bool IsLanConnection()
{
int dwflags = 0;
//return True if LAN connection
Status1 = InternetGetConnectedStateEx(ref CntType1, CntName1, CntNameLen1, 0);
return Convert.ToBoolean(CntType1) & Convert.ToBoolean(LanConnection) & Status1;
}


private void Button1_Click(object sender, System.EventArgs e)
{
if (! (IsModemConnection()))
{

MessageBox.Show("Not Connected To Internet via Modem!!!");
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
}
else
{

MessageBox.Show("Connected To Internet Via modem !!!");
}

}
private void Button2_Click(object sender, System.EventArgs e)
{
if (! (IsLanConnection()))
{
DissNotWritten = false;
MessageBox.Show("Not Connected on LAN !!!");
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
}
else
{
MessageBox.Show("Connected on LAN !!!");
}
}

Pls modify this csharp program as written in vb.net Out put is dieeerent in c sharp.
Please check out the above program

Thanks in Advance
regards,
sanjeev
GeneralUnderlining text in buttons Pin
livez1-Jun-05 20:54
livez1-Jun-05 20:54 
GeneralRe: Underlining text in buttons Pin
mav.northwind1-Jun-05 21:20
mav.northwind1-Jun-05 21:20 
GeneralRe: Underlining text in buttons Pin
Susan Hernandez3-Jun-05 14:37
Susan Hernandez3-Jun-05 14:37 
Generali wanna help Pin
Member 14597831-Jun-05 20:36
Member 14597831-Jun-05 20:36 
GeneralRe: i wanna help Pin
Anonymous2-Jun-05 6:37
Anonymous2-Jun-05 6:37 
GeneralRe: i wanna help Pin
Dave Kreskowiak2-Jun-05 7:19
mveDave Kreskowiak2-Jun-05 7:19 
GeneralRe: i wanna help Pin
Dave Kreskowiak3-Jun-05 5:12
mveDave Kreskowiak3-Jun-05 5:12 
QuestionSystem.Uri bug?? Pin
Jason Manfield1-Jun-05 14:30
Jason Manfield1-Jun-05 14:30 
AnswerRe: System.Uri bug?? Pin
Miszou2-Jun-05 8:52
Miszou2-Jun-05 8:52 
GeneralRe: System.Uri bug?? Pin
Jason Manfield2-Jun-05 9:19
Jason Manfield2-Jun-05 9:19 
GeneralAccess 2000 and C# Pin
Tom Wright1-Jun-05 12:04
Tom Wright1-Jun-05 12:04 
GeneralRe: Access 2000 and C# Pin
Christian Graus1-Jun-05 12:09
protectorChristian Graus1-Jun-05 12:09 
GeneralRe: Access 2000 and C# Pin
Dave Kreskowiak2-Jun-05 7:15
mveDave Kreskowiak2-Jun-05 7:15 
GeneralInvokeMember problem Pin
Eirik Hoem1-Jun-05 11:44
sussEirik Hoem1-Jun-05 11:44 
GeneralRe: InvokeMember problem *Solved* Pin
Anonymous1-Jun-05 13:18
Anonymous1-Jun-05 13:18 
GeneralRe: InvokeMember problem *Un-Solved* Pin
Eirik Hoem1-Jun-05 14:21
sussEirik Hoem1-Jun-05 14:21 
GeneralRe: InvokeMember problem Pin
S. Senthil Kumar2-Jun-05 2:37
S. Senthil Kumar2-Jun-05 2:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.