In the previously written C # code, the following is the dial-up and disconnection functions [in the Vista/XP system, Netcom's dial-up test passed, and Netcom's dial-up client does not need to be installed ]:
Private Static mutex = new mutex ();
Private process dailer = new process ();
Int DESC;
// Creating the extern function...
[Dllimport ("wininet. dll")]
Private extern static bool internetgetconnectedstate (Out int description, int reservedvalue );
// Creating a function that uses the API function...
// If out parameter returns 18 then fail, if 81 then success
Public void isconnectedtointernet ()
{
Internetgetconnectedstate (Out DESC, 0 );
}
Private void stopdailer ()
{
While (DESC = 81)
{
Lock (dailer)
{
If (! Isalive ("rundll32 "))
{
Mutex. waitone ();
Dailer. startinfo. filename = "rundll32.exe ";
Dailer. startinfo. Arguments = "iedkcs32.dll closerasconnections ";
Dailer. Start ();
// Thread. Sleep (1000 );
Mutex. releasemutex ();
}
}
Isconnectedtointernet ();
}
Dailer. Close ();
}
Private void startdailer ()
{
While (DESC! = 81)
{
Lock (dailer)
{
If (! Isalive ("rasdial "))
{
Mutex. waitone ();
Dailer. startinfo. filename = "rasdial.exe ";
// Txtdail. Text broadband dialing name, txtname. Text Broadband User name [Note: Encrypted, not your original user name], txtpwd. Text Broadband User Password
Dailer. startinfo. Arguments = txtdail. Text. Trim () + "" + txtname. Text. Trim () + "" + txtpwd. Text. Trim ();
Dailer. Start ();
Mutex. releasemutex ();
}
// Thread. Sleep (1000 );
}
Isconnectedtointernet ();
}
Dailer. Close ();
}
Private bool isalive (string name)
{
Process [] PS = process. getprocessesbyname (name );
If (PS. length> 0)
{
Return true;
}
Else
{
Return false;
}
}