110,537
社区成员
发帖
与我相关
我的任务
分享
class BoHao
{
private static Mutex mutex = new Mutex();
private Process dailer = new Process();
public int Desc;
string EntryName = "宽带连接";
string user = "lanxxxxxxxxxx";
string pwd = "********";
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
// 返回18失败,返回81成功
public int IsConnectedToInternet()
{
InternetGetConnectedState(out Desc, 0);
return Desc;
}
public void StartDailer()
{
try
{
if (!IsAlive("rasdial"))
{
mutex.WaitOne();
dailer.StartInfo.FileName = "rasdial.exe";
dailer.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
dailer.StartInfo.Arguments = EntryName + " " + user + " " + pwd;
dailer.Start();
mutex.ReleaseMutex();
}
}
catch (Exception ee)
{
ee.ToString();
}
finally
{
}
dailer.Close();
}
private bool IsAlive(string name)
{
Process[] ps = Process.GetProcessesByName(name);
if (ps.Length > 0)
{
return true;
}
else
{
return false;
}
}
}